alamb opened a new issue, #5293:
URL: https://github.com/apache/arrow-datafusion/issues/5293

   **Describe the bug**
   https://github.com/apache/arrow-datafusion/pull/5132 introduced a regression 
regarding ordering by alias columns that were also marked as DISTINCT
   
   **To Reproduce**
   ```sql
   DataFusion CLI v18.0.0
   ❯ create or replace table t as select column1 as value, column2 as time from 
(select * from (values
     (1, timestamp '2022-01-01 00:00:30'),
     (2, timestamp '2022-01-01 01:00:10'),
     (3, timestamp '2022-01-02 00:00:20')
   ) as sq) as sq
   ;
   0 rows in set. Query took 0.007 seconds.
   ❯ SELECT DISTINCT time as "first_seen" FROM t ORDER BY time;
   Plan("For SELECT DISTINCT, ORDER BY expressions time must appear in select 
list")
   ```
   
   **Expected behavior**
   The query should succeed and produce the same answer as posgres
   
   ```sql
   postgres=# postgres=# create  table t as select column1 as value, column2 as 
time from (select * from (values
     (1, timestamp '2022-01-01 00:00:30'),
     (2, timestamp '2022-01-01 01:00:10'),
     (3, timestamp '2022-01-02 00:00:20')
   ) as sq) as sq
   ;
   SELECT 3
   postgres=# SELECT DISTINCT time as "first_seen" FROM t ORDER BY time;
        first_seen
   ---------------------
    2022-01-01 00:00:30
    2022-01-01 01:00:10
    2022-01-02 00:00:20
   (3 rows)
   ```
   
   
   **Additional context**
   We found this internally in IOx. 


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

Reply via email to