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
36 changes: 32 additions & 4 deletions datafusion/functions-aggregate/src/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ mod min_max_bytes;

use arrow::array::{
ArrayRef, BinaryArray, BinaryViewArray, BooleanArray, Date32Array, Date64Array,
Decimal128Array, Decimal256Array, Float16Array, Float32Array, Float64Array,
Int16Array, Int32Array, Int64Array, Int8Array, IntervalDayTimeArray,
Decimal128Array, Decimal256Array, DurationMicrosecondArray, DurationMillisecondArray,
DurationNanosecondArray, DurationSecondArray, Float16Array, Float32Array,
Float64Array, Int16Array, Int32Array, Int64Array, Int8Array, IntervalDayTimeArray,
IntervalMonthDayNanoArray, IntervalYearMonthArray, LargeBinaryArray,
LargeStringArray, StringArray, StringViewArray, Time32MillisecondArray,
Time32SecondArray, Time64MicrosecondArray, Time64NanosecondArray,
Expand Down Expand Up @@ -513,6 +514,33 @@ 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 Expand Up @@ -1594,7 +1622,7 @@ mod tests {
assert_eq!(
min_res,
ScalarValue::IntervalYearMonth(Some(IntervalYearMonthType::make_value(
-2, 4
-2, 4,
)))
);

Expand All @@ -1606,7 +1634,7 @@ mod tests {
assert_eq!(
max_res,
ScalarValue::IntervalYearMonth(Some(IntervalYearMonthType::make_value(
5, 34
5, 34,
)))
);

Expand Down
20 changes: 20 additions & 0 deletions datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
Expand Up @@ -3700,6 +3700,26 @@ SELECT MIN(value), MAX(value) FROM timestampmicrosecond
statement ok
DROP TABLE timestampmicrosecond;

# min_duration, max_duration
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;

# max_bool
statement ok
CREATE TABLE max_bool (value BOOLEAN);
Expand Down
Loading