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
42 changes: 36 additions & 6 deletions datafusion/physical-expr/src/aggregate/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ use arrow::datatypes::{
};
use arrow::{
array::{
ArrayRef, BinaryArray, BooleanArray, Date32Array, Date64Array, Float32Array,
Float64Array, Int16Array, Int32Array, Int64Array, Int8Array, LargeBinaryArray,
LargeStringArray, StringArray, Time32MillisecondArray, Time32SecondArray,
Time64MicrosecondArray, Time64NanosecondArray, TimestampMicrosecondArray,
TimestampMillisecondArray, TimestampNanosecondArray, TimestampSecondArray,
UInt16Array, UInt32Array, UInt64Array, UInt8Array,
ArrayRef, BinaryArray, BooleanArray, Date32Array, Date64Array,
DurationMicrosecondArray, DurationMillisecondArray, DurationNanosecondArray,
DurationSecondArray, Float32Array, Float64Array, Int16Array, Int32Array,
Int64Array, Int8Array, LargeBinaryArray, LargeStringArray, StringArray,
Time32MillisecondArray, Time32SecondArray, Time64MicrosecondArray,
Time64NanosecondArray, TimestampMicrosecondArray, TimestampMillisecondArray,
TimestampNanosecondArray, TimestampSecondArray, UInt16Array, UInt32Array,
UInt64Array, UInt8Array,
},
datatypes::Field,
};
Expand Down Expand Up @@ -408,6 +410,34 @@ macro_rules! min_max_batch {
$OP
)
}
DataType::Duration(TimeUnit::Second) => {
typed_min_max_batch!($VALUES, DurationSecondArray, DurationSecond, $OP)
}
DataType::Duration(TimeUnit::Millisecond) => {
typed_min_max_batch!(
$VALUES,
DurationMillisecondArray,
DurationMillisecond,
$OP
)
}
DataType::Duration(TimeUnit::Microsecond) => {
typed_min_max_batch!(
$VALUES,
DurationMicrosecondArray,
DurationMicrosecond,
$OP
)
}
DataType::Duration(TimeUnit::Nanosecond) => {
typed_min_max_batch!(
$VALUES,
DurationNanosecondArray,
DurationNanosecond,
$OP
)
}

other => {
// This should have been handled before
return internal_err!(
Expand Down
19 changes: 19 additions & 0 deletions datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
Expand Up @@ -3730,6 +3730,25 @@ select * from t;
NULL NULL Row 2 Y
2021-01-01 2021-01-01T00:00:00 Row 3 Y

# aggregate_duration_min_max
statement ok
create table d
as values
(arrow_cast(1, 'Duration(Second)'), arrow_cast(2, 'Duration(Millisecond)'), arrow_cast(3, 'Duration(Microsecond)'), arrow_cast(4, 'Duration(Nanosecond)')),
(arrow_cast(11, 'Duration(Second)'),arrow_cast(22, 'Duration(Millisecond)'), arrow_cast(33, 'Duration(Microsecond)'), arrow_cast(44, 'Duration(Nanosecond)'));

query ????
SELECT min(column1), min(column2), min(column3), min(column4) FROM d;
----
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

query ????
SELECT max(column1), max(column2), max(column3), max(column4) FROM d;
----
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

statement ok
drop table d;

# aggregate_timestamps_sum
query error
Expand Down
Loading