kosiew commented on code in PR #27412:
URL: https://github.com/apache/datafusion/pull/27412#discussion_r4768412897
##########
datafusion/physical-expr/src/expressions/case.rs:
##########
@@ -1509,9 +1509,14 @@ fn evaluate_predicate(predicate: &Arc<dyn PhysicalExpr>)
-> Result<NullableInter
&RecordBatchOptions::new().with_row_count(Some(1)),
)?;
+ // Only a deterministic expression over literals has a value without input
rows
+ let constant = !predicate.exists(|e| {
Review Comment:
Blocking: Repeated eligibility checks introduce O(n²) traversal for
left-deep AND predicates where evaluation previously short-circuited. Avoid
reclassifying overlapping subtrees and add a visit-count test to verify the
work bound.
##########
datafusion/physical-expr/src/expressions/case.rs:
##########
@@ -1523,10 +1528,10 @@ fn evaluate_predicate(predicate: &Arc<dyn
PhysicalExpr>) -> Result<NullableInter
}
return Ok(NullableInterval::ANY_TRUTH_VALUE);
Review Comment:
Blocking: This loses the known-NULL comparison proof, causing `SUM(CASE WHEN
a < random() THEN a ELSE 0.0 END)` over nullable `a` to fail physical planning.
Preserve the UNKNOWN proof without evaluating `random()` and add an aggregate
SLT regression.
##########
datafusion/physical-expr/src/expressions/case.rs:
##########
@@ -1509,9 +1509,14 @@ fn evaluate_predicate(predicate: &Arc<dyn PhysicalExpr>)
-> Result<NullableInter
&RecordBatchOptions::new().with_row_count(Some(1)),
)?;
+ // Only a deterministic expression over literals has a value without input
rows
Review Comment:
Consider renaming `constant` to `can_evaluate_on_dummy_batch` and
documenting the literal-leaf and volatility requirements. As the `pi()` test
demonstrates, an ineligible expression can still have a constant value.
##########
datafusion/sqllogictest/test_files/case.slt:
##########
@@ -41,6 +41,25 @@ FROM (
----
6
+# CASE nullability does not depend on a draw of a volatile condition
+query B
+SELECT count(x1) + count(x2) + count(x3) + count(x4)
Review Comment:
Could we add a deterministic test using a volatile Boolean UDF with a
literal argument, asserting nullable output and zero invocations? This
independently exercises the volatility guard and allows simplifying the
probabilistic SQL test.
--
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]