fzlzjerry commented on code in PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#discussion_r3916588637


##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -2304,6 +2332,39 @@ fn inlist_except(mut l1: InList, l2: &InList) -> 
Result<Expr> {
     Ok(Expr::InList(l1))
 }
 
+/// Set algebra on `IN` lists is only sound if nullable list items are not
+/// discarded. When the tested expression is nullable, preserve the NULL branch
+/// of an otherwise constant result explicitly.
+fn simplify_inlist_set_operation(
+    info: &SimplifyContext,
+    left: &InList,
+    right: &InList,
+    result: Expr,
+) -> Option<Expr> {
+    let list_items_are_non_nullable = left
+        .list
+        .iter()
+        .chain(&right.list)
+        .all(|item| matches!(info.nullable(item), Ok(false)));
+
+    if !list_items_are_non_nullable {
+        return None;
+    }
+
+    if !is_true(&result) && !is_false(&result) {

Review Comment:
   `is_bool_lit` also matches `Boolean(None)`, whereas this branch must only 
handle non-null boolean constants. I kept the explicit `is_true` / `is_false` 
check and added a regression test for a NULL boolean result.



##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -2304,6 +2332,39 @@ fn inlist_except(mut l1: InList, l2: &InList) -> 
Result<Expr> {
     Ok(Expr::InList(l1))
 }
 
+/// Set algebra on `IN` lists is only sound if nullable list items are not
+/// discarded. When the tested expression is nullable, preserve the NULL branch
+/// of an otherwise constant result explicitly.
+fn simplify_inlist_set_operation(

Review Comment:
   Updated — the helper now returns `Result<Option<Expr>>`. Nullability errors 
from both list items and the tested expression propagate through all four 
callers, with regression coverage for both error paths.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to