[SPARK-48091][SQL] Preserve aliases inside lambda when ExtractGenerator restructures plan#55892
Open
shrirangmhalgi wants to merge 1 commit into
Open
Conversation
…or restructures plan
ExtractGenerator called trimNonTopLevelAliases on all project list items before extracting the generator. This stripped aliases inside lambda functions (e.g., struct(x.as("data"))) before they could be resolved into struct field names by CreateStruct.
Now only uses trimNonTopLevelAliases for pattern matching to detect generators, but preserves the original untrimmed expression for non-generator project items.
Author
|
@cloud-fan / @dongjoon-hyun / @sarutak could you please review this PR. |
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?
Fix
ExtractGeneratorto preserve aliases inside lambda functions when restructuring the plan.Previously,
ExtractGeneratorcalledtrimNonTopLevelAliaseson all expressions in the project list before extracting the generator. This stripped aliases inside lambda functions (e.g., struct(x.as("data"))) beforeCreateStructcould resolve them into struct field names.The fix uses
trimNonTopLevelAliasesonly for pattern matching (to detect generators viaAliasedGenerator), but preserves the original untrimmed expression for non-generator project items.Why are the changes needed?
When using explode together with transform in the same
select statement, aliases used inside the transformed column'sstruct()are ignored. Field names become auto-generated (x_1, x_2) instead of the user-specified alias. This only happens with the DataFrame/Dataset API, not with SQL.Does this PR introduce any user-facing change?
Yes. Struct field aliases inside transform lambdas are now correctly preserved when explode (or any generator) is in the same
select.How was this patch tested?
Added a test in
GeneratorFunctionSuiteverifying that struct field aliases are preserved when explode and transform are used together, including single and multiple aliases.Was this patch authored or co-authored using generative AI tooling?
Yes.