This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new e82707ec5a feat: simplify null in list (#8691)
e82707ec5a is described below
commit e82707ec5a912dc5f23e9fe89bea5f49ec64688f
Author: Ashim Sedhain <[email protected]>
AuthorDate: Mon Jan 1 11:44:27 2024 -0600
feat: simplify null in list (#8691)
GH-8688
---
.../src/simplify_expressions/expr_simplifier.rs | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs
b/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs
index 5a300e2ff2..7d09aec7e7 100644
--- a/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs
+++ b/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs
@@ -481,6 +481,14 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for
Simplifier<'a, S> {
lit(negated)
}
+ // null in (x, y, z) --> null
+ // null not in (x, y, z) --> null
+ Expr::InList(InList {
+ expr,
+ list: _,
+ negated: _,
+ }) if is_null(&expr) => lit_bool_null(),
+
// expr IN ((subquery)) -> expr IN (subquery), see ##5529
Expr::InList(InList {
expr,
@@ -3096,6 +3104,18 @@ mod tests {
assert_eq!(simplify(in_list(col("c1"), vec![], false)), lit(false));
assert_eq!(simplify(in_list(col("c1"), vec![], true)), lit(true));
+ // null in (...) --> null
+ assert_eq!(
+ simplify(in_list(lit_bool_null(), vec![col("c1"), lit(1)], false)),
+ lit_bool_null()
+ );
+
+ // null not in (...) --> null
+ assert_eq!(
+ simplify(in_list(lit_bool_null(), vec![col("c1"), lit(1)], true)),
+ lit_bool_null()
+ );
+
assert_eq!(
simplify(in_list(col("c1"), vec![lit(1)], false)),
col("c1").eq(lit(1))