-
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
feat(datafusion-functions-aggregate): add support for lists and other nested types in min
and max
#13991
base: main
Are you sure you want to change the base?
feat(datafusion-functions-aggregate): add support for lists and other nested types in min
and max
#13991
Changes from all commits
dba5552
ed910e4
2a8ea48
c92a1be
9b2370b
c997b21
6990c4e
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
//! [`Min`] and [`MinAccumulator`] accumulator for the `min` function | ||
|
||
mod min_max_bytes; | ||
mod min_max_generic; | ||
|
||
use arrow::array::{ | ||
ArrayRef, BinaryArray, BinaryViewArray, BooleanArray, Date32Array, Date64Array, | ||
|
@@ -54,6 +55,10 @@ use arrow::datatypes::{ | |
}; | ||
|
||
use crate::min_max::min_max_bytes::MinMaxBytesAccumulator; | ||
use crate::min_max::min_max_generic::{ | ||
GenericMaxAccumulator, GenericMinAccumulator, GenericSlidingMaxAccumulator, | ||
GenericSlidingMinAccumulator, | ||
}; | ||
use datafusion_common::ScalarValue; | ||
use datafusion_expr::{ | ||
function::AccumulatorArgs, Accumulator, AggregateUDFImpl, Documentation, Signature, | ||
|
@@ -230,7 +235,13 @@ impl AggregateUDFImpl for Max { | |
} | ||
|
||
fn accumulator(&self, acc_args: AccumulatorArgs) -> Result<Box<dyn Accumulator>> { | ||
Ok(Box::new(MaxAccumulator::try_new(acc_args.return_type)?)) | ||
if acc_args.return_type.is_nested() { | ||
Ok(Box::new(GenericMaxAccumulator::try_new( | ||
acc_args.return_type, | ||
)?)) | ||
} else { | ||
Ok(Box::new(MaxAccumulator::try_new(acc_args.return_type)?)) | ||
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. The pattern used in other accumulators is slightly different I think -- It would have a function on For example, something like if MaxAccumulator::supports_type(&acc_args.return_type) {
Ok(Box::new(MaxAccumulator::try_new(acc_args.return_type)?))
} else {
Ok(Box::new(GenericMaxAccumulator::try_new(
acc_args.return_type,
)?))
} This is a minor detail and not required, I just wanted to point it out |
||
} | ||
} | ||
|
||
fn aliases(&self) -> &[String] { | ||
|
@@ -337,7 +348,13 @@ impl AggregateUDFImpl for Max { | |
&self, | ||
args: AccumulatorArgs, | ||
) -> Result<Box<dyn Accumulator>> { | ||
Ok(Box::new(SlidingMaxAccumulator::try_new(args.return_type)?)) | ||
if args.return_type.is_nested() { | ||
Ok(Box::new(GenericSlidingMaxAccumulator::try_new( | ||
args.return_type, | ||
)?)) | ||
} else { | ||
Ok(Box::new(SlidingMaxAccumulator::try_new(args.return_type)?)) | ||
} | ||
} | ||
|
||
fn is_descending(&self) -> Option<bool> { | ||
|
@@ -1051,7 +1068,13 @@ impl AggregateUDFImpl for Min { | |
} | ||
|
||
fn accumulator(&self, acc_args: AccumulatorArgs) -> Result<Box<dyn Accumulator>> { | ||
Ok(Box::new(MinAccumulator::try_new(acc_args.return_type)?)) | ||
if acc_args.return_type.is_nested() { | ||
Ok(Box::new(GenericMinAccumulator::try_new( | ||
acc_args.return_type, | ||
)?)) | ||
} else { | ||
Ok(Box::new(MinAccumulator::try_new(acc_args.return_type)?)) | ||
} | ||
} | ||
|
||
fn aliases(&self) -> &[String] { | ||
|
@@ -1158,7 +1181,13 @@ impl AggregateUDFImpl for Min { | |
&self, | ||
args: AccumulatorArgs, | ||
) -> Result<Box<dyn Accumulator>> { | ||
Ok(Box::new(SlidingMinAccumulator::try_new(args.return_type)?)) | ||
if args.return_type.is_nested() { | ||
Ok(Box::new(GenericSlidingMinAccumulator::try_new( | ||
args.return_type, | ||
)?)) | ||
} else { | ||
Ok(Box::new(SlidingMinAccumulator::try_new(args.return_type)?)) | ||
} | ||
} | ||
|
||
fn is_descending(&self) -> Option<bool> { | ||
|
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.
If you wanted to make this less verbose you could probably do something like