Skip to content

Commit 0123a16

Browse files
authored
V39: Support Duration in min/max agg functions (#283)
* Support Duration in min/max agg functions * Attempt to fix build * Attempt to fix build - Fix chrono version * Revert "Attempt to fix build - Fix chrono version" This reverts commit fd76fe6. * Revert "Attempt to fix build" This reverts commit 9114b86. --------- Co-authored-by: svranesevic <svranesevic@users.noreply.github.com>
1 parent ca2d007 commit 0123a16

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

datafusion/physical-expr/src/aggregate/min_max.rs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ use arrow::datatypes::{
3030
};
3131
use arrow::{
3232
array::{
33-
ArrayRef, BinaryArray, BooleanArray, Date32Array, Date64Array, Float32Array,
34-
Float64Array, Int16Array, Int32Array, Int64Array, Int8Array, LargeBinaryArray,
35-
LargeStringArray, StringArray, Time32MillisecondArray, Time32SecondArray,
36-
Time64MicrosecondArray, Time64NanosecondArray, TimestampMicrosecondArray,
37-
TimestampMillisecondArray, TimestampNanosecondArray, TimestampSecondArray,
38-
UInt16Array, UInt32Array, UInt64Array, UInt8Array,
33+
ArrayRef, BinaryArray, BooleanArray, Date32Array, Date64Array,
34+
DurationMicrosecondArray, DurationMillisecondArray, DurationNanosecondArray,
35+
DurationSecondArray, Float32Array, Float64Array, Int16Array, Int32Array,
36+
Int64Array, Int8Array, LargeBinaryArray, LargeStringArray, StringArray,
37+
Time32MillisecondArray, Time32SecondArray, Time64MicrosecondArray,
38+
Time64NanosecondArray, TimestampMicrosecondArray, TimestampMillisecondArray,
39+
TimestampNanosecondArray, TimestampSecondArray, UInt16Array, UInt32Array,
40+
UInt64Array, UInt8Array,
3941
},
4042
datatypes::Field,
4143
};
@@ -408,6 +410,34 @@ macro_rules! min_max_batch {
408410
$OP
409411
)
410412
}
413+
DataType::Duration(TimeUnit::Second) => {
414+
typed_min_max_batch!($VALUES, DurationSecondArray, DurationSecond, $OP)
415+
}
416+
DataType::Duration(TimeUnit::Millisecond) => {
417+
typed_min_max_batch!(
418+
$VALUES,
419+
DurationMillisecondArray,
420+
DurationMillisecond,
421+
$OP
422+
)
423+
}
424+
DataType::Duration(TimeUnit::Microsecond) => {
425+
typed_min_max_batch!(
426+
$VALUES,
427+
DurationMicrosecondArray,
428+
DurationMicrosecond,
429+
$OP
430+
)
431+
}
432+
DataType::Duration(TimeUnit::Nanosecond) => {
433+
typed_min_max_batch!(
434+
$VALUES,
435+
DurationNanosecondArray,
436+
DurationNanosecond,
437+
$OP
438+
)
439+
}
440+
411441
other => {
412442
// This should have been handled before
413443
return internal_err!(

datafusion/sqllogictest/test_files/aggregate.slt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3730,6 +3730,25 @@ select * from t;
37303730
NULL NULL Row 2 Y
37313731
2021-01-01 2021-01-01T00:00:00 Row 3 Y
37323732

3733+
# aggregate_duration_min_max
3734+
statement ok
3735+
create table d
3736+
as values
3737+
(arrow_cast(1, 'Duration(Second)'), arrow_cast(2, 'Duration(Millisecond)'), arrow_cast(3, 'Duration(Microsecond)'), arrow_cast(4, 'Duration(Nanosecond)')),
3738+
(arrow_cast(11, 'Duration(Second)'),arrow_cast(22, 'Duration(Millisecond)'), arrow_cast(33, 'Duration(Microsecond)'), arrow_cast(44, 'Duration(Nanosecond)'));
3739+
3740+
query ????
3741+
SELECT min(column1), min(column2), min(column3), min(column4) FROM d;
3742+
----
3743+
0 days 0 hours 0 mins 1 secs 0 days 0 hours 0 mins 0.002 secs 0 days 0 hours 0 mins 0.000003 secs 0 days 0 hours 0 mins 0.000000004 secs
3744+
3745+
query ????
3746+
SELECT max(column1), max(column2), max(column3), max(column4) FROM d;
3747+
----
3748+
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
3749+
3750+
statement ok
3751+
drop table d;
37333752

37343753
# aggregate_timestamps_sum
37353754
query error

0 commit comments

Comments
 (0)