-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for DISTINCT + ORDER BY in ARRAY_AGG #14413
base: main
Are you sure you want to change the base?
Conversation
9400d72
to
8eaacd6
Compare
8eaacd6
to
f23681c
Compare
@@ -193,3 +193,149 @@ pub fn merge_ordered_arrays( | |||
|
|||
Ok((merged_values, merged_orderings)) | |||
} | |||
|
|||
#[cfg(test)] | |||
mod tests { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this tests from
mod tests { |
merge_ordered_arrays
function present in this file, and nothing related to ARRAY_AGG
.
As I added there some unit tests that do test ARRAY_AGG
, I though that it might be a good idea to move these ones out to a more suitable place.
if values.len() != 1 { | ||
return internal_err!("expects single batch"); | ||
if values.is_empty() { | ||
return Ok(()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As now the distinct accumulator can accept more than 1 batch because of the ordering, removing this restriction was necessary.
Close/reopen to rerun CI |
Which issue does this PR close?
Closes #12371.
Rationale for this change
Completing ARRAY_AGG functionality as a prerequisite for adding the full functionality of STRING_AGG in #14412
What changes are included in this PR?
Adds a Postgres-style support for DISTINCT + ORDER_BY functionality, allowing users to issue statements like:
Note that there's a limitation that prohibits ordering by an expression that is not the same as the ARRAY_AGG argument. For example, the following queries are invalid:
This is the same limitation that exists on Postgres, example in Postgres fiddle
Are these changes tested?
yes, both in unit tests and sqllogictests
Are there any user-facing changes?
Users will now be able to issue ARRAY_AGG calls mixing DISTINCT and ORDER_BY clauses