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
29 changes: 28 additions & 1 deletion datafusion/physical-expr/src/aggregate/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use crate::aggregate::groups_accumulator::prim_op::PrimitiveGroupsAccumulator;
use crate::{AggregateExpr, PhysicalExpr};
use arrow::compute;
use arrow::datatypes::{
DataType, Date32Type, Date64Type, Time32MillisecondType, Time32SecondType,
DataType, Date32Type, Date64Type, DurationMicrosecondType, DurationMillisecondType,
DurationNanosecondType, DurationSecondType, Time32MillisecondType, Time32SecondType,
Time64MicrosecondType, Time64NanosecondType, TimeUnit, TimestampMicrosecondType,
TimestampMillisecondType, TimestampNanosecondType, TimestampSecondType,
};
Expand Down Expand Up @@ -193,6 +194,7 @@ impl AggregateExpr for Max {
| Time32(_)
| Time64(_)
| Timestamp(_, _)
| Duration(_)
)
}

Expand Down Expand Up @@ -241,6 +243,18 @@ impl AggregateExpr for Max {
Timestamp(Nanosecond, _) => {
instantiate_max_accumulator!(self, i64, TimestampNanosecondType)
}
Duration(Second) => {
instantiate_max_accumulator!(self, i64, DurationSecondType)
}
Duration(Millisecond) => {
instantiate_max_accumulator!(self, i64, DurationMillisecondType)
}
Duration(Microsecond) => {
instantiate_max_accumulator!(self, i64, DurationMicrosecondType)
}
Duration(Nanosecond) => {
instantiate_max_accumulator!(self, i64, DurationNanosecondType)
}
Decimal128(_, _) => {
instantiate_max_accumulator!(self, i128, Decimal128Type)
}
Expand Down Expand Up @@ -945,6 +959,7 @@ impl AggregateExpr for Min {
| Time32(_)
| Time64(_)
| Timestamp(_, _)
| Duration(_)
)
}

Expand Down Expand Up @@ -992,6 +1007,18 @@ impl AggregateExpr for Min {
Timestamp(Nanosecond, _) => {
instantiate_min_accumulator!(self, i64, TimestampNanosecondType)
}
Duration(Second) => {
instantiate_min_accumulator!(self, i64, DurationSecondType)
}
Duration(Millisecond) => {
instantiate_min_accumulator!(self, i64, DurationMillisecondType)
}
Duration(Microsecond) => {
instantiate_min_accumulator!(self, i64, DurationMicrosecondType)
}
Duration(Nanosecond) => {
instantiate_min_accumulator!(self, i64, DurationNanosecondType)
}
Decimal128(_, _) => {
instantiate_min_accumulator!(self, i128, Decimal128Type)
}
Expand Down
30 changes: 28 additions & 2 deletions datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
Expand Up @@ -3734,8 +3734,8 @@ NULL NULL Row 2 Y
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)'));
(arrow_cast(1, 'Duration(Second)'), arrow_cast(2, 'Duration(Millisecond)'), arrow_cast(3, 'Duration(Microsecond)'), arrow_cast(4, 'Duration(Nanosecond)'), 1),
(arrow_cast(11, 'Duration(Second)'),arrow_cast(22, 'Duration(Millisecond)'), arrow_cast(33, 'Duration(Microsecond)'), arrow_cast(44, 'Duration(Nanosecond)'), 1);

query ????
SELECT min(column1), min(column2), min(column3), min(column4) FROM d;
Expand All @@ -3747,6 +3747,32 @@ 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

# GROUP BY follows a different code path
query ????I
SELECT min(column1), min(column2), min(column3), min(column4), column5 FROM d GROUP BY column5;
----
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 1

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

statement ok
INSERT INTO d VALUES
(arrow_cast(3, 'Duration(Second)'), arrow_cast(1, 'Duration(Millisecond)'), arrow_cast(7, 'Duration(Microsecond)'), arrow_cast(2, 'Duration(Nanosecond)'), 1),
(arrow_cast(0, 'Duration(Second)'), arrow_cast(9, 'Duration(Millisecond)'), arrow_cast(5, 'Duration(Microsecond)'), arrow_cast(8, 'Duration(Nanosecond)'), 1);

query ????I
SELECT max(column1), max(column2), max(column3), max(column4), column5 FROM d GROUP BY column5 ORDER BY column5;
----
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 1

query ????I
SELECT min(column1), min(column2), min(column3), min(column4), column5 FROM d GROUP BY column5 ORDER BY column5;
----
0 days 0 hours 0 mins 0 secs 0 days 0 hours 0 mins 0.001 secs 0 days 0 hours 0 mins 0.000003 secs 0 days 0 hours 0 mins 0.000000002 secs 1

statement ok
drop table d;

Expand Down
Loading