Skip to content

Commit 1c0dcad

Browse files
fix: disallow specify both order_by and within_group (apache#16606)
1 parent d66d6b9 commit 1c0dcad

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

datafusion/sql/src/expr/function.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
227227
OVER is for window functions, whereas WITHIN GROUP is for ordered set aggregate functions");
228228
}
229229

230+
if !order_by.is_empty() && !within_group.is_empty() {
231+
return plan_err!("ORDER BY and WITHIN GROUP clauses cannot be used together in the same aggregate function. ");
232+
}
233+
230234
// If function is a window function (it has an OVER clause),
231235
// it shouldn't have ordering requirement as function argument
232236
// required ordering should be defined in OVER clause.

datafusion/sqllogictest/test_files/aggregate.slt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7053,3 +7053,6 @@ FROM (VALUES ('a'), ('d'), ('c'), ('a')) t(a_varchar);
70537053
----
70547054
[a, c, d]
70557055

7056+
query error Error during planning: ORDER BY and WITHIN GROUP clauses cannot be used together in the same aggregate function.
7057+
SELECT array_agg(a_varchar order by a_varchar) WITHIN GROUP (ORDER BY a_varchar)
7058+
FROM (VALUES ('a'), ('d'), ('c'), ('a')) t(a_varchar);

0 commit comments

Comments
 (0)