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

   ### What changes were proposed in this pull request?
   
   Fix the `Mode.sql()` method to correctly display the sort direction in the 
generated SQL string for `WITHIN GROUP (ORDER BY ...)` clauses.
   
   The `reverseOpt` field in `Mode` was being mapped to the wrong SQL output:
   - `reverse=true` (Ascending) was incorrectly producing `DESC`
   - `reverse=false` (Descending) was incorrectly omitting `DESC`
   
   The fix swaps the two branches so the SQL output matches the original 
user-specified sort direction.
   
   ### Why are the changes needed?
   
   `mode() WITHIN GROUP (ORDER BY col)` was displaying as `ORDER BY col DESC` 
in schema column names and analyzer output, and vice versa. This caused 
incorrect schema names and broken SQL roundtrips.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. Schema column names for `mode() WITHIN GROUP (ORDER BY ...)` now 
correctly reflect the sort direction.
   
   ### How was this patch tested?
   
   - Unit test in `AggregateExpressionSuite` verifying `sql()` output for both 
ASC and DESC.
   - Integration test in `DataFrameAggregateSuite` verifying schema column 
names and SQL roundtrip.
   - Updated SQL golden files (`mode.sql.out` analyzer-results and results).
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Yes, co-authored with Kiro.


-- 
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