isidentical commented on code in PR #4090:
URL: https://github.com/apache/arrow-datafusion/pull/4090#discussion_r1013349637


##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -365,6 +367,38 @@ impl<'a, S: SimplifyInfo> ExprRewriter for Simplifier<'a, 
S> {
                     None => lit_bool_null(),
                 }
             }
+            // expr IN () --> false
+            // expr NOT IN () --> true
+            Expr::InList {
+                expr,
+                list,
+                negated,
+            } if list.is_empty() && *expr != Expr::Literal(ScalarValue::Null) 
=> {
+                lit(negated)
+            }
+
+            // if expr is a single column reference:
+            // expr IN (A, B, ...) --> (expr = A) OR (expr = B) OR (expr = C)
+            Expr::InList {
+                expr,
+                list,
+                negated,
+            } if list.len() == 1

Review Comment:
   Took me a while to understand why the length of 1 is special-cased. Maybe we 
could mention that the column reference check is strictly for ensuring that we 
are not doing an unnecessary evaluation of the left side over and over again 
(so a length of 1 is always fine or if it is something simple as a column 
access then it is also fine).



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