Skip to content

Commit 406aa8b

Browse files
committed
GroupsAccumulator for Duration
1 parent f5821b9 commit 406aa8b

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

datafusion/functions-aggregate/src/min_max.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ use arrow::array::{
3333
};
3434
use arrow::compute;
3535
use arrow::datatypes::{
36-
DataType, Decimal128Type, Decimal256Type, Float16Type, Float32Type, Float64Type,
37-
Int16Type, Int32Type, Int64Type, Int8Type, IntervalUnit, UInt16Type, UInt32Type,
38-
UInt64Type, UInt8Type,
36+
DataType, Decimal128Type, Decimal256Type, DurationMicrosecondType,
37+
DurationMillisecondType, DurationNanosecondType, DurationSecondType, Float16Type,
38+
Float32Type, Float64Type, Int16Type, Int32Type, Int64Type, Int8Type, IntervalUnit,
39+
UInt16Type, UInt32Type, UInt64Type, UInt8Type,
3940
};
4041
use datafusion_common::stats::Precision;
4142
use datafusion_common::{
@@ -264,6 +265,7 @@ impl AggregateUDFImpl for Max {
264265
| Binary
265266
| LargeBinary
266267
| BinaryView
268+
| Duration(_)
267269
)
268270
}
269271

@@ -318,6 +320,18 @@ impl AggregateUDFImpl for Max {
318320
Timestamp(Nanosecond, _) => {
319321
primitive_max_accumulator!(data_type, i64, TimestampNanosecondType)
320322
}
323+
Duration(Second) => {
324+
primitive_max_accumulator!(data_type, i64, DurationSecondType)
325+
}
326+
Duration(Millisecond) => {
327+
primitive_max_accumulator!(data_type, i64, DurationMillisecondType)
328+
}
329+
Duration(Microsecond) => {
330+
primitive_max_accumulator!(data_type, i64, DurationMicrosecondType)
331+
}
332+
Duration(Nanosecond) => {
333+
primitive_max_accumulator!(data_type, i64, DurationNanosecondType)
334+
}
321335
Decimal128(_, _) => {
322336
primitive_max_accumulator!(data_type, i128, Decimal128Type)
323337
}
@@ -1118,6 +1132,7 @@ impl AggregateUDFImpl for Min {
11181132
| Binary
11191133
| LargeBinary
11201134
| BinaryView
1135+
| Duration(_)
11211136
)
11221137
}
11231138

@@ -1172,6 +1187,18 @@ impl AggregateUDFImpl for Min {
11721187
Timestamp(Nanosecond, _) => {
11731188
primitive_min_accumulator!(data_type, i64, TimestampNanosecondType)
11741189
}
1190+
Duration(Second) => {
1191+
primitive_min_accumulator!(data_type, i64, DurationSecondType)
1192+
}
1193+
Duration(Millisecond) => {
1194+
primitive_min_accumulator!(data_type, i64, DurationMillisecondType)
1195+
}
1196+
Duration(Microsecond) => {
1197+
primitive_min_accumulator!(data_type, i64, DurationMicrosecondType)
1198+
}
1199+
Duration(Nanosecond) => {
1200+
primitive_min_accumulator!(data_type, i64, DurationNanosecondType)
1201+
}
11751202
Decimal128(_, _) => {
11761203
primitive_min_accumulator!(data_type, i128, Decimal128Type)
11771204
}

datafusion/sqllogictest/test_files/aggregate.slt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3835,6 +3835,20 @@ SELECT max(column1), max(column2), max(column3), max(column4), column5 FROM d GR
38353835
----
38363836
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
38373837

3838+
statement ok
3839+
INSERT INTO d VALUES
3840+
(arrow_cast(3, 'Duration(Second)'), arrow_cast(1, 'Duration(Millisecond)'), arrow_cast(7, 'Duration(Microsecond)'), arrow_cast(2, 'Duration(Nanosecond)'), 1),
3841+
(arrow_cast(0, 'Duration(Second)'), arrow_cast(9, 'Duration(Millisecond)'), arrow_cast(5, 'Duration(Microsecond)'), arrow_cast(8, 'Duration(Nanosecond)'), 1);
3842+
3843+
query ????I
3844+
SELECT max(column1), max(column2), max(column3), max(column4), column5 FROM d GROUP BY column5 ORDER BY column5;
3845+
----
3846+
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
3847+
3848+
query ????I
3849+
SELECT min(column1), min(column2), min(column3), min(column4), column5 FROM d GROUP BY column5 ORDER BY column5;
3850+
----
3851+
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
38383852

38393853
statement ok
38403854
drop table d;

0 commit comments

Comments
 (0)