AdamGS commented on code in PR #24258:
URL: https://github.com/apache/datafusion/pull/24258#discussion_r3915286140
##########
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:
nit - is this `!is_bool_lit(&result)`?
--
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]