Determine whether a predicate can restrict NULLs. e.g. `c0 > 8` return true; `c0 IS NULL` return false.
(
predicate: Expr,
join_cols_of_predicate: impl IntoIterator<Item = &'a Column>,
)
| 112 | /// `c0 > 8` return true; |
| 113 | /// `c0 IS NULL` return false. |
| 114 | pub fn is_restrict_null_predicate<'a>( |
| 115 | predicate: Expr, |
| 116 | join_cols_of_predicate: impl IntoIterator<Item = &'a Column>, |
| 117 | ) -> Result<bool> { |
| 118 | if matches!(predicate, Expr::Column(_)) { |
| 119 | return Ok(true); |
| 120 | } |
| 121 | |
| 122 | // If result is single `true`, return false; |
| 123 | // If result is single `NULL` or `false`, return true; |
| 124 | Ok( |
| 125 | match evaluate_expr_with_null_column(predicate, join_cols_of_predicate)? { |
| 126 | ColumnarValue::Array(array) => { |
| 127 | if array.len() == 1 { |
| 128 | let boolean_array = as_boolean_array(&array)?; |
| 129 | boolean_array.is_null(0) || !boolean_array.value(0) |
| 130 | } else { |
| 131 | false |
| 132 | } |
| 133 | } |
| 134 | ColumnarValue::Scalar(scalar) => matches!( |
| 135 | scalar, |
| 136 | ScalarValue::Boolean(None) | ScalarValue::Boolean(Some(false)) |
| 137 | ), |
| 138 | }, |
| 139 | ) |
| 140 | } |
| 141 | |
| 142 | /// Determines if an expression will always evaluate to null. |
| 143 | /// `c0 + 8` return true |
searching dependent graphs…