-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Support multiple ordered array_agg aggregations
#16625
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
Changes from 4 commits
c32eb2f
cf4d8ae
4cd992c
9b7e94d
a551e7d
3bacde9
90db3d2
5f00ec4
134da5a
1420f8d
5c1bce9
8a1abe8
a1031e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -223,6 +223,7 @@ impl AggregateExprBuilder { | |
|
|
||
| let return_field = fun.return_field(&input_exprs_fields)?; | ||
| let is_nullable = fun.is_nullable(); | ||
| // TODO rename AggregateExprBuilder::alias to name | ||
| let name = match alias { | ||
| None => { | ||
| return internal_err!( | ||
|
|
@@ -575,18 +576,10 @@ impl AggregateFunctionExpr { | |
| ReversedUDAF::NotSupported => None, | ||
| ReversedUDAF::Identical => Some(self.clone()), | ||
| ReversedUDAF::Reversed(reverse_udf) => { | ||
| let mut name = self.name().to_string(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think removing this may have other unintended effects. I will request some more eyes on this
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Alternatively to the fix, I can block reversing for beneficial functions and thus hide the problem for now. Would it be preferred for this PR? |
||
| // If the function is changed, we need to reverse order_by clause as well | ||
| // i.e. First(a order by b asc null first) -> Last(a order by b desc null last) | ||
| if self.fun().name() != reverse_udf.name() { | ||
| replace_order_by_clause(&mut name); | ||
| } | ||
| replace_fn_name_clause(&mut name, self.fun.name(), reverse_udf.name()); | ||
|
|
||
| AggregateExprBuilder::new(reverse_udf, self.args.to_vec()) | ||
| .order_by(self.order_bys.iter().map(|e| e.reverse()).collect()) | ||
| .schema(Arc::new(self.schema.clone())) | ||
| .alias(name) | ||
| .alias(self.name()) | ||
| .with_ignore_nulls(self.ignore_nulls) | ||
| .with_distinct(self.is_distinct) | ||
| .with_reversed(!self.is_reversed) | ||
|
|
@@ -684,32 +677,3 @@ impl PartialEq for AggregateFunctionExpr { | |
| .all(|(this_arg, other_arg)| this_arg.eq(other_arg)) | ||
| } | ||
| } | ||
|
|
||
| fn replace_order_by_clause(order_by: &mut String) { | ||
| let suffixes = [ | ||
| (" DESC NULLS FIRST]", " ASC NULLS LAST]"), | ||
| (" ASC NULLS FIRST]", " DESC NULLS LAST]"), | ||
| (" DESC NULLS LAST]", " ASC NULLS FIRST]"), | ||
| (" ASC NULLS LAST]", " DESC NULLS FIRST]"), | ||
| ]; | ||
|
|
||
| if let Some(start) = order_by.find("ORDER BY [") { | ||
| if let Some(end) = order_by[start..].find(']') { | ||
| let order_by_start = start + 9; | ||
| let order_by_end = start + end; | ||
|
|
||
| let column_order = &order_by[order_by_start..=order_by_end]; | ||
| for (suffix, replacement) in suffixes { | ||
| if column_order.ends_with(suffix) { | ||
| let new_order = column_order.replace(suffix, replacement); | ||
| order_by.replace_range(order_by_start..=order_by_end, &new_order); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn replace_fn_name_clause(aggr_name: &mut String, fn_name_old: &str, fn_name_new: &str) { | ||
| *aggr_name = aggr_name.replace(fn_name_old, fn_name_new); | ||
| } | ||
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.
Adding this new field should trigger adding equals/hash_value implementations.
Being fixed in #17065