viirya opened a new pull request, #60399:
URL: https://github.com/apache/spark/pull/60399

   ### What changes were proposed in this pull request?
   
   `GeneratePredicateHelper.generatePredicateCode` becomes the only 
implementation of the algorithm that orders the conjuncts of a filter condition 
and its `IsNotNull` checks in the generated code.
   
   - `generatePredicateCode` takes a new optional argument, the states of the 
common subexpressions to eliminate from the conjuncts. It evaluates each state 
right before the first conjunct that references it, after the `IsNotNull` 
checks of that conjunct, generates the conjuncts with the states, and generates 
the checks without them.
   - `FilterExec.doConsume` keeps what is specific to it: the decision to 
eliminate (a non-cheap common subexpression exists and the configs allow it), 
the evaluation of the input variables that the states read, and the creation of 
the states. It then calls `generatePredicateCode` in both cases.
   - The comments that described the two copies and how they had to be kept in 
sync are replaced by a list of the invariants on the single implementation.
   
   The aggregate `FILTER` clause (`AggregateCodegenSupport`), the other caller 
of `generatePredicateCode`, passes no states and is not affected.
   
   ### Why are the changes needed?
   
   `FilterExec.doConsume` re-implemented this algorithm for the conditions it 
eliminates common subexpressions from, and the two copies were kept in sync 
only by comments ("Any change to this algorithm must be mirrored there (and 
vice versa)"). Fixes such as SPARK-51356 and SPARK-60315 had to be applied to 
both, and a change to one copy alone silently makes a filter behave differently 
depending on whether a common subexpression is eliminated.
   
   The copies had no behavioral difference, but they were not the same either: 
with subexpression elimination, the checks on the columns a conjunct references 
were generated with the states visible, while the other checks were explicitly 
generated without them. All checks are now generated without the states.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. The generated code without subexpression elimination is the same as 
before. With it, the code differs in whitespace only.
   
   ### How was this patch tested?
   
   - A new test in `WholeStageCodegenSuite` runs 23 conjunctions, mixing 
columns that can be NULL, written and inferred `IS NOT NULL` checks on columns 
and on expressions, conjuncts that can be NULL, common subexpressions and 
conjuncts that can raise an error, including the cases of SPARK-51356, 
SPARK-60315 and SPARK-60332. For each, it compares the rows, or the error 
condition, across the subexpression elimination configs, with whole-stage 
codegen on and off, in ANSI and non-ANSI mode, with 
`spark.sql.legacy.filterShortCircuitOnNullConjunct` on and off, and checks that 
the condition takes the code path it is meant to cover. The test also passes 
without this change.
   - Compared the whole-stage code generated before and after this change for 
21 conditions, as a filter and as an aggregate `FILTER`, under the combinations 
of ANSI mode, the legacy behavior and 
`spark.sql.subexpressionElimination.filterExec.enabled`: identical without 
subexpression elimination, and identical up to whitespace with it, apart from 
the parameter order of two split subexpression functions, which also varies 
between two runs of the same code.
   - Existing tests: `WholeStageCodegenSuite`, `DataFrameAggregateSuite`, 
`DataFrameSuite`, `MergeIntoDataFrameSuite`, 
`CodegenSubexpressionEliminationSuite`, `SubexpressionEliminationSuite`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code
   
   This pull request and its description were written by Isaac.
   


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