Skip to content

Commit b42243b

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 b42243b

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

datafusion/functions-aggregate/src/min_max.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
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

@@ -28,6 +27,8 @@ use arrow::array::{
2827
Time32SecondArray, Time64MicrosecondArray, Time64NanosecondArray,
2928
TimestampMicrosecondArray, TimestampMillisecondArray, TimestampNanosecondArray,
3029
TimestampSecondArray, UInt16Array, UInt32Array, UInt64Array, UInt8Array,
30+
DurationMicrosecondArray, DurationMillisecondArray, DurationNanosecondArray,
31+
DurationSecondArray,
3132
};
3233
use arrow::compute;
3334
use arrow::datatypes::{
@@ -514,6 +515,33 @@ macro_rules! min_max_batch {
514515
$OP
515516
)
516517
}
518+
DataType::Duration(TimeUnit::Second) => {
519+
typed_min_max_batch!($VALUES, DurationSecondArray, DurationSecond, $OP)
520+
}
521+
DataType::Duration(TimeUnit::Millisecond) => {
522+
typed_min_max_batch!(
523+
$VALUES,
524+
DurationMillisecondArray,
525+
DurationMillisecond,
526+
$OP
527+
)
528+
}
529+
DataType::Duration(TimeUnit::Microsecond) => {
530+
typed_min_max_batch!(
531+
$VALUES,
532+
DurationMicrosecondArray,
533+
DurationMicrosecond,
534+
$OP
535+
)
536+
}
537+
DataType::Duration(TimeUnit::Nanosecond) => {
538+
typed_min_max_batch!(
539+
$VALUES,
540+
DurationNanosecondArray,
541+
DurationNanosecond,
542+
$OP
543+
)
544+
}
517545
other => {
518546
// This should have been handled before
519547
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)