apache / datafusion

Apache DataFusion SQL Query Engine
https://datafusion.apache.org/
Apache License 2.0
5.89k stars 1.11k forks source link

Support different aggregate expression (outside SELECT list) in ORDER BY list #12007

Open 2010YOUY01 opened 4 weeks ago

2010YOUY01 commented 4 weeks ago

Is your feature request related to a problem or challenge?

In aggregate query with order-by: order-by list should support expressions with group by columns, or aggregated aggregate columns, this syntax is widely supported (by DuckDB, postgres and likely many others)

For aggregate function in order by list case, now DataFusion only supports aggregate functions which have appeared in SELECT list

See example

-- Setup
DataFusion CLI v41.0.0
> create table t1 (groupby1 int, agg1 int, agg2 int);
-- This is supported
select groupby1, sum(agg1) 
from t1
group by groupby1
order by groupby1, sum(agg1);

-- Not supported yet in DataFusion
select groupby1, sum(agg1) 
from t1
group by groupby1
order by max(agg2);

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

Additional context

No response

Rachelint commented 4 weeks ago

Interesting, I want to try it.

Rachelint commented 4 weeks ago

take