[WIP][SPARK-50361][SQL] Fix Lateral Column Alias in ORDER BY Bugs #48903
+403
−26
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?
Why are the changes needed?
For 1,
An invalid case, such as
SELECT MAX(id) AS id2 FROM range(1) ORDER BY AVG(id2)
, is considered valid in versions before 3.2.x. Since version 3.2, a refactoring pull request accidentally 'fixes' this case; however, the error message is not straightforward.This error message somewhat confuses users when debugging/upgrading.
For 2, it's bugfix, we shall not ignore the AMBIGUOUS_LATERAL_COLUMN_ALIAS but go further resolution
In this pull request, we explicitly address this issue as we did for standard aggregates.
Does this PR introduce any user-facing change?
Yes, Aggregates using Lateral Column Alias in ORDER BY throws LATERAL_COLUMN_ALIAS_IN_AGG instead of RESOLVED_ATTRIBUTE_MISSING_FROM_INPUT.
How was this patch tested?
new tests
Was this patch authored or co-authored using generative AI tooling?
NO