MCPcopy Create free account
hub / github.com/apache/datafusion / is_restrict_null_predicate

Function is_restrict_null_predicate

datafusion/optimizer/src/utils.rs:114–140  ·  view source on GitHub ↗

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>,
)

Source from the content-addressed store, hash-verified

112/// `c0 > 8` return true;
113/// `c0 IS NULL` return false.
114pub 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

Callers 1

Calls 5

as_boolean_arrayFunction · 0.85
lenMethod · 0.45
is_nullMethod · 0.45
valueMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…