Apache DataFusion SQL Query Engine
Keep aggregate udaf schema names unique when missing an order-by (#17731)
wiedldbdcfd431295a
diff --git a/datafusion/expr/src/udaf.rs b/datafusion/expr/src/udaf.rsindex 0279c671a7..fa71a76c09 100644--- a/datafusion/expr/src/udaf.rs+++ b/datafusion/expr/src/udaf.rs@@ -805,7 +805,7 @@ pub fn udaf_default_schema_name<F: AggregateUDFImpl + ?Sized>(// exclude the first function argument(= column) in ordered set aggregate function,// because it is duplicated with the WITHIN GROUP clause in schema name.- let args = if func.is_ordered_set_aggregate() {+ let args = if func.is_ordered_set_aggregate() && !order_by.is_empty() {&args[1..]} else {&args[..]diff --git a/datafusion/sqllogictest/test_files/aggregate.slt b/datafusion/sqllogictest/test_files/aggregate.sltindex 4601d595e3..888b425c7a 100644--- a/datafusion/sqllogictest/test_files/aggregate.slt+++ b/datafusion/sqllogictest/test_files/aggregate.slt@@ -1835,6 +1835,29 @@ c 122d 124e 115++# using approx_percentile_cont on 2 columns with same signature+query TII+SELECT c1, approx_percentile_cont(c2, 0.95) AS c2, approx_percentile_cont(c3, 0.95) AS c3 FROM aggregate_test_100 GROUP BY 1 ORDER BY 1+----+a 5 73+b 5 68+c 5 122+d 5 124+e 5 115++# error is unique to this UDAF+query TRR+SELECT c1, avg(c2) AS c2, avg(c3) AS c3 FROM aggregate_test_100 GROUP BY 1 ORDER BY 1+----+a 2.857142857143 -18.333333333333+b 3.263157894737 -5.842105263158+c 2.666666666667 -1.333333333333+d 2.444444444444 25.444444444444+e 3 40.333333333333+++query TISELECT c1, approx_percentile_cont(0.95) WITHIN GROUP (ORDER BY c3 DESC) AS c3_p95 FROM aggregate_test_100 GROUP BY 1 ORDER BY 1----