Skip to content

Commit 3f27988

Browse files
svranesevicavantgardnerio
authored andcommitted
Support Duration in min/max agg functions (#283) (apache#15310) v47
* 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 <[email protected]>
1 parent d23ed2a commit 3f27988

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

datafusion/functions-aggregate/src/min_max.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
// under the License.
1616

1717
//! [`Max`] and [`MaxAccumulator`] accumulator for the `max` function
18-
//! [`Min`] and [`MinAccumulator`] accumulator for the `min` function
1918
2019
mod min_max_bytes;
2120

2221
use arrow::array::{
2322
ArrayRef, BinaryArray, BinaryViewArray, BooleanArray, Date32Array, Date64Array,
24-
Decimal128Array, Decimal256Array, Float16Array, Float32Array, Float64Array,
25-
Int16Array, Int32Array, Int64Array, Int8Array, IntervalDayTimeArray,
23+
Decimal128Array, Decimal256Array, DurationMicrosecondArray, DurationMillisecondArray,
24+
DurationNanosecondArray, DurationSecondArray, Float16Array, Float32Array,
25+
Float64Array, Int16Array, Int32Array, Int64Array, Int8Array, IntervalDayTimeArray,
2626
IntervalMonthDayNanoArray, IntervalYearMonthArray, LargeBinaryArray,
2727
LargeStringArray, StringArray, StringViewArray, Time32MillisecondArray,
2828
Time32SecondArray, Time64MicrosecondArray, Time64NanosecondArray,
@@ -514,6 +514,33 @@ macro_rules! min_max_batch {
514514
$OP
515515
)
516516
}
517+
DataType::Duration(TimeUnit::Second) => {
518+
typed_min_max_batch!($VALUES, DurationSecondArray, DurationSecond, $OP)
519+
}
520+
DataType::Duration(TimeUnit::Millisecond) => {
521+
typed_min_max_batch!(
522+
$VALUES,
523+
DurationMillisecondArray,
524+
DurationMillisecond,
525+
$OP
526+
)
527+
}
528+
DataType::Duration(TimeUnit::Microsecond) => {
529+
typed_min_max_batch!(
530+
$VALUES,
531+
DurationMicrosecondArray,
532+
DurationMicrosecond,
533+
$OP
534+
)
535+
}
536+
DataType::Duration(TimeUnit::Nanosecond) => {
537+
typed_min_max_batch!(
538+
$VALUES,
539+
DurationNanosecondArray,
540+
DurationNanosecond,
541+
$OP
542+
)
543+
}
517544
other => {
518545
// This should have been handled before
519546
return internal_err!(

datafusion/sqllogictest/test_files/aggregate.slt

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

4231+
# aggregate_duration_min_max
4232+
statement ok
4233+
create table d
4234+
as values
4235+
(arrow_cast(1, 'Duration(Second)'), arrow_cast(2, 'Duration(Millisecond)'), arrow_cast(3, 'Duration(Microsecond)'), arrow_cast(4, 'Duration(Nanosecond)')),
4236+
(arrow_cast(11, 'Duration(Second)'),arrow_cast(22, 'Duration(Millisecond)'), arrow_cast(33, 'Duration(Microsecond)'), arrow_cast(44, 'Duration(Nanosecond)'));
4237+
4238+
query ????
4239+
SELECT min(column1), min(column2), min(column3), min(column4) FROM d;
4240+
----
4241+
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
4242+
4243+
query ????
4244+
SELECT max(column1), max(column2), max(column3), max(column4) FROM d;
4245+
----
4246+
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
4247+
4248+
statement ok
4249+
drop table d;
42314250

42324251
# aggregate_timestamps_sum
42334252
query error

0 commit comments

Comments
 (0)