Skip to content

Commit 80efd2b

Browse files
Lordwormsxinlifoobar
authored andcommitted
Using display_name for Expr::Aggregation (apache#11020)
1 parent f41d79d commit 80efd2b

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

datafusion/core/src/physical_planner.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,6 +1918,7 @@ pub fn create_aggregate_expr_and_maybe_filter(
19181918
// unpack (nested) aliased logical expressions, e.g. "sum(col) as total"
19191919
let (name, e) = match e {
19201920
Expr::Alias(Alias { expr, name, .. }) => (name.clone(), expr.as_ref()),
1921+
Expr::AggregateFunction(_) => (e.display_name().unwrap_or(physical_name(e)?), e),
19211922
_ => (physical_name(e)?, e),
19221923
};
19231924

datafusion/sqllogictest/test_files/expr.slt

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,7 +2473,7 @@ host2 202
24732473
host3 303
24742474

24752475
# TODO: Issue tracked in https://github.com/apache/datafusion/issues/10364
2476-
query error
2476+
query TR
24772477
select
24782478
t2.server['c3'] as host,
24792479
sum((
@@ -2488,6 +2488,10 @@ select
24882488
) t2
24892489
where t2.server['c3'] IS NOT NULL
24902490
group by t2.server['c3'] order by host;
2491+
----
2492+
host1 101
2493+
host2 202
2494+
host3 303
24912495

24922496
# can have 2 projections with aggr(short_circuited), with different short-circuited expr
24932497
query TRR
@@ -2559,7 +2563,7 @@ host2 2.2 202
25592563
host3 3.3 303
25602564

25612565
# TODO: Issue tracked in https://github.com/apache/datafusion/issues/10364
2562-
query error
2566+
query TRR
25632567
select
25642568
t2.server['c3'] as host,
25652569
sum((
@@ -2579,6 +2583,10 @@ select
25792583
) t2
25802584
where t2.server['c3'] IS NOT NULL
25812585
group by t2.server['c3'] order by host;
2586+
----
2587+
host1 1.1 101
2588+
host2 2.2 202
2589+
host3 3.3 303
25822590

25832591
# can have 2 projections with aggr(short_circuited), with the same short-circuited expr (e.g. coalesce)
25842592
query TRR
@@ -2587,3 +2595,28 @@ select t2."struct(t1.time,t1.load1,t1.load2,t1.host)"['c3'] as host, sum(coalesc
25872595
host1 1.1 101
25882596
host2 2.2 202
25892597
host3 3.3 303
2598+
2599+
statement ok
2600+
set datafusion.sql_parser.dialect = 'Postgres';
2601+
2602+
statement ok
2603+
create table t (a float) as values (1), (2), (3);
2604+
2605+
query TT
2606+
explain select min(a) filter (where a > 1) as x from t;
2607+
----
2608+
logical_plan
2609+
01)Projection: MIN(t.a) FILTER (WHERE t.a > Int64(1)) AS x
2610+
02)--Aggregate: groupBy=[[]], aggr=[[MIN(t.a) FILTER (WHERE t.a > Float32(1)) AS MIN(t.a) FILTER (WHERE t.a > Int64(1))]]
2611+
03)----TableScan: t projection=[a]
2612+
physical_plan
2613+
01)ProjectionExec: expr=[MIN(t.a) FILTER (WHERE t.a > Int64(1))@0 as x]
2614+
02)--AggregateExec: mode=Single, gby=[], aggr=[MIN(t.a) FILTER (WHERE t.a > Int64(1))]
2615+
03)----MemoryExec: partitions=1, partition_sizes=[1]
2616+
2617+
2618+
statement ok
2619+
drop table t;
2620+
2621+
statement ok
2622+
set datafusion.sql_parser.dialect = 'Generic';

0 commit comments

Comments
 (0)