emecii commented on code in PR #25143:
URL: https://github.com/apache/datafusion/pull/25143#discussion_r3989414124


##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -2432,6 +2436,26 @@ fn simplify_inlist_set_operation(
     }))
 }
 
+/// Conservatively checks the inputs whose evaluation can change when lowering
+/// CASE to AND/OR. [`Expr`] has no general fallibility analysis: only columns 
and
+/// literals are admitted from conditional branches, including later WHEN 
conditions.
+/// The first WHEN already runs on every row, but must not be volatile because
+/// the rewrite can evaluate it more than once.
+fn can_lower_case_to_boolean(
+    when_then_expr: &[(Box<Expr>, Box<Expr>)],
+    else_expr: Option<&Expr>,
+) -> bool {
+    let is_leaf = |expr: &Expr| matches!(expr, Expr::Column(_) | 
Expr::Literal(..));
+    when_then_expr.iter().enumerate().all(|(i, (when, then))| {
+        is_leaf(then)
+            && if i == 0 {
+                !when.is_volatile()

Review Comment:
   Fixed in 3d52a60d0. The guard now requires the first WHEN, every later WHEN, 
and all branch outputs to be columns or literals. I added the CAST(s AS INT) 
regression with identical false outputs and a unit case proving the CASE is 
preserved.



##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -2432,6 +2436,26 @@ fn simplify_inlist_set_operation(
     }))
 }
 
+/// Conservatively checks the inputs whose evaluation can change when lowering
+/// CASE to AND/OR. [`Expr`] has no general fallibility analysis: only columns 
and
+/// literals are admitted from conditional branches, including later WHEN 
conditions.

Review Comment:
   Updated in 3d52a60d0. The invariant comment now explicitly states that all 
WHEN conditions and branch outputs must be columns or literals.



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