[SPARK-37467][SQL] Consolidate subexpression elimination code for whole stage and non-whole stage #51269
+70
−176
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
This PR consolidates the code paths for subexpression elimination in whole stage and non-whole stage codegen. Whole stage codegen seemed to be mostly a superset of the non-whole stage subexpression elimination, just with whole stage not using the codegen context to track subexpressions.
This cleans things up by making non-whole stage use the same stateless approach as whole-stage so there is a single code path for all subexpression elimination, simplifying future improvements.
It shouldn't result in any functionality changes, but there are slight differences in the generated code as a result of this:
I'm not a JVM expert but I don't expect a mutable state to cause a performance regression over an inlined variable, especially since they are used in the split case anyway, and this may make future code splitting improvements simpler.
Why are the changes needed?
Currently, there are different code paths to handle subexpression elimination in whole stage and non-whole stage codegen. This makes it harder to add new capabilities to subexpression elimination having to deal with independent code paths.
Does this PR introduce any user-facing change?
No, just slight changes in generated code.
How was this patch tested?
Existing unit tests.
Was this patch authored or co-authored using generative AI tooling?
No