MichaelScofield opened a new issue, #27705:
URL: https://github.com/apache/datafusion/issues/27705

   ### Describe the bug
   
   A `SELECT DISTINCT` query fails during planning when its `ORDER BY` repeats 
the arithmetic expression from the select list. This happens both with and 
without an output alias.
   
   ### To reproduce
   
   Reproduced with DataFusion 57.0.0-dev at 
`6a060586ed85d2ff71837b6d818b7eddc075b699` using `SessionContext::sql`.
   
   ```sql
   CREATE TABLE t AS SELECT * FROM (VALUES (2), (1), (2)) AS input(a);
   
   SELECT DISTINCT a + 1 FROM t ORDER BY a + 1;
   SELECT DISTINCT a + 1 AS v FROM t ORDER BY a + 1;
   ```
   
   Both queries return the same error:
   
   ```text
   Error during planning: For SELECT DISTINCT, ORDER BY expressions t.a must 
appear in select list
   ```
   
   ### Expected behavior
   
   Both queries should return two rows, `2` followed by `3`. The sort key is 
the same expression already produced by the select list. Ordering by its alias 
already returns the expected rows:
   
   ```sql
   SELECT DISTINCT a + 1 AS v FROM t ORDER BY v;
   ```
   


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