AssHero commented on code in PR #2750:
URL: https://github.com/apache/arrow-datafusion/pull/2750#discussion_r902103396


##########
datafusion/sql/src/planner.rs:
##########
@@ -2584,6 +2587,230 @@ fn extract_join_keys(
     }
 }
 
+/// Recursively traversese expr, if expr returns false when
+/// any inputs are null, treats columns of both sides as nonnullable columns.
+///
+/// For and/or expr, extracts from all sub exprs and merges the columns.
+/// For or expr, if one of sub exprs returns true, discards all columns from 
or expr.
+/// For IS NOT NULL/NOT expr, always returns false for NULL input.
+///     extracts columns from these exprs.
+/// For all other exprs, fall through
+fn extract_nonnullable_columns(
+    expr: &Expr,
+    columns: &mut Vec<Column>,
+    top_level: bool,
+) -> Result<()> {
+    match expr {
+        Expr::Column(col) => {
+            columns.push(col.clone());
+            Ok(())
+        }
+        Expr::BinaryExpr { left, op, right } => match op {
+            // If one of the inputs are null for these operators, the results 
should be false.
+            Operator::Eq
+            | Operator::NotEq
+            | Operator::Lt
+            | Operator::LtEq
+            | Operator::Gt
+            | Operator::GtEq => {
+                extract_nonnullable_columns(left, columns, false)?;
+                extract_nonnullable_columns(right, columns, false)
+            }
+            Operator::And => {
+                if !top_level {

Review Comment:
   > Will something like `Not(And(a > 10, b < 10))` hits this check and gets 
ignored?
   
   YES. If not from top_level, we can handle And expr as Or expr, this is 
better.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to