Skip to content

Commit e82707e

Browse files
authored
feat: simplify null in list (#8691)
GH-8688
1 parent 77c2180 commit e82707e

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,14 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for Simplifier<'a, S> {
481481
lit(negated)
482482
}
483483

484+
// null in (x, y, z) --> null
485+
// null not in (x, y, z) --> null
486+
Expr::InList(InList {
487+
expr,
488+
list: _,
489+
negated: _,
490+
}) if is_null(&expr) => lit_bool_null(),
491+
484492
// expr IN ((subquery)) -> expr IN (subquery), see ##5529
485493
Expr::InList(InList {
486494
expr,
@@ -3096,6 +3104,18 @@ mod tests {
30963104
assert_eq!(simplify(in_list(col("c1"), vec![], false)), lit(false));
30973105
assert_eq!(simplify(in_list(col("c1"), vec![], true)), lit(true));
30983106

3107+
// null in (...) --> null
3108+
assert_eq!(
3109+
simplify(in_list(lit_bool_null(), vec![col("c1"), lit(1)], false)),
3110+
lit_bool_null()
3111+
);
3112+
3113+
// null not in (...) --> null
3114+
assert_eq!(
3115+
simplify(in_list(lit_bool_null(), vec![col("c1"), lit(1)], true)),
3116+
lit_bool_null()
3117+
);
3118+
30993119
assert_eq!(
31003120
simplify(in_list(col("c1"), vec![lit(1)], false)),
31013121
col("c1").eq(lit(1))

0 commit comments

Comments
 (0)