kosiew commented on code in PR #26634:
URL: https://github.com/apache/datafusion/pull/26634#discussion_r4548813554
##########
datafusion/physical-optimizer/src/projection_pushdown.rs:
##########
@@ -433,6 +465,28 @@ impl<'a> JoinFilterRewriter<'a> {
}
}
+/// Returns the number of leading children of `expr` that are evaluated for
every row, or `None`
+/// if all children are. The remaining children may be skipped for some rows.
+///
+/// Mirrors `conditional_children` in the logical `CommonSubexprEliminate`
rule.
+fn always_evaluated_child_count(expr: &dyn PhysicalExpr) -> Option<usize> {
+ if let Some(case) = expr.downcast_ref::<CaseExpr>() {
+ // The children are the optional base expression, then each WHEN/THEN
pair, then the
+ // optional ELSE. Only the base expression and the first WHEN are
always evaluated.
+ Some(usize::from(case.expr().is_some()) + 1)
Review Comment:
A simple CASE does not always evaluate its first WHEN. When the base is
NULL, `CaseBody::case_when_with_expr` skips WHEN evaluation, so `Some(2)` can
hoist a guarded cast and cause an error. Please return `Some(1)` for both CASE
forms and add a regression using `CASE r.v WHEN CAST(l.s AS INT) THEN 1 ELSE 0
END = 1` with `r.v = NULL` and `l.s = 'x'`, verifying zero rows without an
error.
--
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]