yaooqinn opened a new pull request, #48903:
URL: https://github.com/apache/spark/pull/48903

   ### What changes were proposed in this pull request?
   
   Aggreges using Lateral Column Alias in ORDER BY should throw 
LATERAL_COLUMN_ALIAS_IN_AGGREGATE_FUNC
   
   
   ### Why are the changes needed?
   
   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.
   
   ```scala
   [MISSING_ATTRIBUTES.RESOLVED_ATTRIBUTE_MISSING_FROM_INPUT] Resolved 
attribute(s) "id2" missing from "id" in operator !Aggregate [max(id#130L) AS 
id2#129L, avg(id2#129L) AS avg(id2#129L)#133].  SQLSTATE: XX000; line 1 pos 36;
   Project [id2#129L]
   +- Sort [avg(id2#129L)#133 ASC NULLS FIRST], true
      +- !Aggregate [max(id#130L) AS id2#129L, avg(id2#129L) AS 
avg(id2#129L)#133]
         +- Range (0, 1, step=1)
   ```
   
   This error message somewhat confuses users when debugging/upgrading.
   
   In this pull request, we explicitly address this issue in the same way 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
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to