[SPARK-45069][SQL] SQL variable should always be resolved after outer reference#42803
Closed
cloud-fan wants to merge 1 commit intoapache:masterfrom
Closed
[SPARK-45069][SQL] SQL variable should always be resolved after outer reference#42803cloud-fan wants to merge 1 commit intoapache:masterfrom
cloud-fan wants to merge 1 commit intoapache:masterfrom
Conversation
cloud-fan
commented
Sep 4, 2023
| try { | ||
| val resolved = innerResolve(expr, isTopLevel = true) | ||
| val withOuterResolved = if (allowOuter) resolveOuterRef(resolved) else resolved | ||
| resolveVariables(withOuterResolved) |
Contributor
Author
There was a problem hiding this comment.
This is the bug. Sometimes we only want to do basic column resolution first, and then try some special resolution logic (see ResolveReferencesInAggregat as an example), and finally resolve outer references. The code before always tried to resolve the SQL variable.
To avoid hitting similar bugs, I refactored the code a bit to have a last resort step for column resolution, which contains resolving outer references and SQL variables.
Contributor
Author
MaxGekk
approved these changes
Sep 11, 2023
Member
|
@cloud-fan We shouldn't backport this to 3.5, correct? |
Contributor
Author
|
@MaxGekk no, sql variable is only in the master branch. |
Contributor
Author
|
thanks for the review, merging to master! |
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 is a bug fix for the recently added SQL variable feature. It's designed to resolve columns to SQL variable as the last resort, but for columns in Aggregate, we may resolve columns to outer reference first.
Why are the changes needed?
bug fix
Does this PR introduce any user-facing change?
yes, the query result can be wrong before this fix
How was this patch tested?
new tests
Was this patch authored or co-authored using generative AI tooling?
no