[SQL] Preserve SELECT-list order when extracting multiple generators - #58710
Draft
vladimirg-db wants to merge 1 commit into
Draft
[SQL] Preserve SELECT-list order when extracting multiple generators#58710vladimirg-db wants to merge 1 commit into
vladimirg-db wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 change makes
ExtractGeneratorpreserve SELECT-list order when it extracts independentgenerator expressions. A generator may still be extracted ahead of an earlier generator when the
earlier generator has a direct or transitive lateral-column-alias dependency on a generator to its
right.
The internal configuration
spark.sql.generator.preserveSelectListOrderdefaults totruefor thenew behavior. Setting it to
falserestores the previous first-ready extraction behavior.Why are the changes needed?
Generator extraction currently happens over multiple analyzer iterations. If a later generator's
children resolve before an earlier generator's children, the later generator is extracted first.
That changes the nesting and evaluation order of the resulting
Generateoperators. The differenceis observable when generator inputs contain nondeterministic expressions or UDFs and can change query
results.
Does this PR introduce any user-facing change?
Yes. Independent generators are now evaluated in SELECT-list order by default. For example, with an
identity UDF registered as
udf:The new behavior returns
(0.0, 10)and(0.0, 20). The previous behavior could return(0.0, 10)and(1.0, 20)because the right generator was extracted first. Settingspark.sql.generator.preserveSelectListOrder=falserestores the previous behavior.How was this patch tested?
Added SQL golden tests for both configuration values. They cover Scala and Python UDFs,
nondeterministic expressions, multiple generators, grouping analytics, direct and transitive
lateral-column-alias dependencies, and a case combining all of them.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Codex (GPT-5)