ranflarion opened a new pull request, #27412: URL: https://github.com/apache/datafusion/pull/27412
## Which issue does this PR close? - Closes #27411. ## Rationale for this change `CASE WHEN random() < 0.5 THEN NULL ELSE a END` over a non-nullable `a` fails at random with `Column 'x' is declared as non-nullable but contains null values`, and a CASE argument of a scalar function whose WHEN reads a column builds and discards an error on every batch, which with the `backtrace` feature and `RUST_BACKTRACE=1` captures a backtrace each time (0.98 s against 6.96 s for the query in #27411). Both come from `CaseExpr::nullable` evaluating the WHEN condition on a one-row batch with no columns: a volatile condition gets a random answer, and a condition over a column fails. ## What changes are included in this PR? `evaluate_predicate` evaluates the condition only when every leaf is a `Literal` and no node is volatile, the same leaf rule #26083 uses for IN list constants. Any other condition goes straight to the AND/OR/NOT bounds that previously ran after the evaluation failed, so a condition over columns gets the same nullability as before without building an error. The cost is that a condition with a non-literal leaf that is nonetheless constant, such as a nullary function the optimizer did not fold (`pi() > 4`), is now treated as possibly true, which is what the logical side's `predicate_bounds` already reports. ## What is the testing strategy for this PR? A new query in `case.slt` aggregates eight volatile CASE columns over a non-nullable column. On main it passes only when all eight draws come out nullable, so it fails on almost every run; with this change it returns `true` every time. `test_case_expression_nullability_with_non_literal_leaf` pins the leaf rule with `pi() > 4`, which main evaluates to false. The existing CASE nullability tests pass unchanged. No benchmark covers `nullable`; the query in #27411 goes from 6.96 s to 0.96 s with `RUST_BACKTRACE=1`. ## Are there any user-facing changes? No API changes. A CASE with a volatile WHEN is reported nullable whenever a reachable branch can produce NULL, and nullability inference no longer builds errors for conditions that read the input. -- 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]
