Skip to content

Commit eae41af

Browse files
wiedlderratic-pattern
authored andcommitted
Keep aggregate udaf schema names unique when missing an order-by
* test: reproducer of bug * fix: make schema names unique for approx_percentile_cont * test: regression test is now resolved
1 parent cb7c62e commit eae41af

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

datafusion/expr/src/udaf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ pub trait AggregateUDFImpl: Debug + Send + Sync {
459459

460460
// exclude the first function argument(= column) in ordered set aggregate function,
461461
// because it is duplicated with the WITHIN GROUP clause in schema name.
462-
let args = if self.is_ordered_set_aggregate() {
462+
let args = if self.is_ordered_set_aggregate() && !order_by.is_empty() {
463463
&args[1..]
464464
} else {
465465
&args[..]

datafusion/sqllogictest/test_files/aggregate.slt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,29 @@ c 122
17711771
d 124
17721772
e 115
17731773

1774+
1775+
# using approx_percentile_cont on 2 columns with same signature
1776+
query TII
1777+
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
1778+
----
1779+
a 5 73
1780+
b 5 68
1781+
c 5 122
1782+
d 5 124
1783+
e 5 115
1784+
1785+
# error is unique to this UDAF
1786+
query TRR
1787+
SELECT c1, avg(c2) AS c2, avg(c3) AS c3 FROM aggregate_test_100 GROUP BY 1 ORDER BY 1
1788+
----
1789+
a 2.857142857143 -18.333333333333
1790+
b 3.263157894737 -5.842105263158
1791+
c 2.666666666667 -1.333333333333
1792+
d 2.444444444444 25.444444444444
1793+
e 3 40.333333333333
1794+
1795+
1796+
17741797
query TI
17751798
SELECT 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
17761799
----

0 commit comments

Comments
 (0)