czhang06 opened a new issue, #27814: URL: https://github.com/apache/datafusion/issues/27814
### Describe the bug Follow-up to #27795 / #27802, which fixed the plain ORDER BY case. With a GROUP BY it's still wrong: ```sql SELECT price AS old_price, 10 - price AS price FROM (SELECT 1 AS price UNION ALL SELECT 5) GROUP BY price ORDER BY price; ``` Got `(1, 9), (5, 5)`, expected `(5, 5), (1, 9)`. Adding `AS s` to the subquery gives the right order. ### To Reproduce Run the query above in `datafusion-cli`. ### Expected behavior `ORDER BY price` should sort by the output column `price`, same as the non-GROUP BY case after #27802. ### Additional context This goes through a different path than #27802. Around line 1483 in `datafusion/sql/src/select.rs`, the ORDER BY key gets rebased and matched against the aliased SELECT items, so `price` matches `price AS old_price`. Thanks @tlfua for spotting this in review. -- 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]
