Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions datafusion/functions-aggregate/src/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ use arrow::array::{
};
use arrow::compute;
use arrow::datatypes::{
DataType, Decimal128Type, Decimal256Type, Float16Type, Float32Type, Float64Type,
Int16Type, Int32Type, Int64Type, Int8Type, IntervalUnit, UInt16Type, UInt32Type,
UInt64Type, UInt8Type,
DataType, Decimal128Type, Decimal256Type, DurationMicrosecondType,
DurationMillisecondType, DurationNanosecondType, DurationSecondType, Float16Type,
Float32Type, Float64Type, Int16Type, Int32Type, Int64Type, Int8Type, IntervalUnit,
UInt16Type, UInt32Type, UInt64Type, UInt8Type,
};
use datafusion_common::stats::Precision;
use datafusion_common::{
Expand Down Expand Up @@ -264,6 +265,7 @@ impl AggregateUDFImpl for Max {
| Binary
| LargeBinary
| BinaryView
| Duration(_)
Copy link
Contributor Author

@shruti2522 shruti2522 Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to add Duration to the list of types supported in groups_accumulator_supported as well.

Hi @alamb, I have added it here and similarly for Min

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry -- I didn't see that for some reason. Thank you 🙏

)
}

Expand Down Expand Up @@ -318,6 +320,18 @@ impl AggregateUDFImpl for Max {
Timestamp(Nanosecond, _) => {
primitive_max_accumulator!(data_type, i64, TimestampNanosecondType)
}
Duration(Second) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to add Duration to the list of types supported in groups_accumulator_supported as well.

primitive_max_accumulator!(data_type, i64, DurationSecondType)
}
Duration(Millisecond) => {
primitive_max_accumulator!(data_type, i64, DurationMillisecondType)
}
Duration(Microsecond) => {
primitive_max_accumulator!(data_type, i64, DurationMicrosecondType)
}
Duration(Nanosecond) => {
primitive_max_accumulator!(data_type, i64, DurationNanosecondType)
}
Decimal128(_, _) => {
primitive_max_accumulator!(data_type, i128, Decimal128Type)
}
Expand Down Expand Up @@ -1118,6 +1132,7 @@ impl AggregateUDFImpl for Min {
| Binary
| LargeBinary
| BinaryView
| Duration(_)
)
}

Expand Down Expand Up @@ -1172,6 +1187,18 @@ impl AggregateUDFImpl for Min {
Timestamp(Nanosecond, _) => {
primitive_min_accumulator!(data_type, i64, TimestampNanosecondType)
}
Duration(Second) => {
primitive_min_accumulator!(data_type, i64, DurationSecondType)
}
Duration(Millisecond) => {
primitive_min_accumulator!(data_type, i64, DurationMillisecondType)
}
Duration(Microsecond) => {
primitive_min_accumulator!(data_type, i64, DurationMicrosecondType)
}
Duration(Nanosecond) => {
primitive_min_accumulator!(data_type, i64, DurationNanosecondType)
}
Decimal128(_, _) => {
primitive_min_accumulator!(data_type, i128, Decimal128Type)
}
Expand Down
14 changes: 14 additions & 0 deletions datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
Expand Up @@ -3835,6 +3835,20 @@ SELECT max(column1), max(column2), max(column3), max(column4), column5 FROM d GR
----
0 days 0 hours 0 mins 11 secs 0 days 0 hours 0 mins 0.022 secs 0 days 0 hours 0 mins 0.000033 secs 0 days 0 hours 0 mins 0.000000044 secs 1

statement ok
INSERT INTO d VALUES
(arrow_cast(3, 'Duration(Second)'), arrow_cast(1, 'Duration(Millisecond)'), arrow_cast(7, 'Duration(Microsecond)'), arrow_cast(2, 'Duration(Nanosecond)'), 1),
(arrow_cast(0, 'Duration(Second)'), arrow_cast(9, 'Duration(Millisecond)'), arrow_cast(5, 'Duration(Microsecond)'), arrow_cast(8, 'Duration(Nanosecond)'), 1);

query ????I
SELECT max(column1), max(column2), max(column3), max(column4), column5 FROM d GROUP BY column5 ORDER BY column5;
----
0 days 0 hours 0 mins 11 secs 0 days 0 hours 0 mins 0.022 secs 0 days 0 hours 0 mins 0.000033 secs 0 days 0 hours 0 mins 0.000000044 secs 1

query ????I
SELECT min(column1), min(column2), min(column3), min(column4), column5 FROM d GROUP BY column5 ORDER BY column5;
----
0 days 0 hours 0 mins 0 secs 0 days 0 hours 0 mins 0.001 secs 0 days 0 hours 0 mins 0.000003 secs 0 days 0 hours 0 mins 0.000000002 secs 1

statement ok
drop table d;
Expand Down