Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with query that has DISTINCT with ORDER BY and aliased select list #5293

Closed
alamb opened this issue Feb 15, 2023 · 0 comments · Fixed by #5307
Closed

Error with query that has DISTINCT with ORDER BY and aliased select list #5293

alamb opened this issue Feb 15, 2023 · 0 comments · Fixed by #5307
Labels
bug Something isn't working

Comments

@alamb
Copy link
Contributor

alamb commented Feb 15, 2023

Describe the bug
#5132 introduced a regression regarding ordering by alias columns that were also marked as DISTINCT

To Reproduce

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant