Skip to content

Commit ae92c52

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 ce74530 commit ae92c52

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
@@ -458,7 +458,7 @@ pub trait AggregateUDFImpl: Debug + DynEq + DynHash + Send + Sync {
458458

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

datafusion/sqllogictest/test_files/aggregate.slt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,29 @@ c 122
18211821
d 124
18221822
e 115
18231823

1824+
1825+
# using approx_percentile_cont on 2 columns with same signature
1826+
query TII
1827+
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
1828+
----
1829+
a 5 73
1830+
b 5 68
1831+
c 5 122
1832+
d 5 124
1833+
e 5 115
1834+
1835+
# error is unique to this UDAF
1836+
query TRR
1837+
SELECT c1, avg(c2) AS c2, avg(c3) AS c3 FROM aggregate_test_100 GROUP BY 1 ORDER BY 1
1838+
----
1839+
a 2.857142857143 -18.333333333333
1840+
b 3.263157894737 -5.842105263158
1841+
c 2.666666666667 -1.333333333333
1842+
d 2.444444444444 25.444444444444
1843+
e 3 40.333333333333
1844+
1845+
1846+
18241847
query TI
18251848
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
18261849
----

0 commit comments

Comments
 (0)