You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by al...@apache.org on 2025/03/20 09:48:35 UTC
(datafusion) branch main updated: Support Duration in min/max agg functions (#15310)
This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new f5821b9d9d Support Duration in min/max agg functions (#15310)
f5821b9d9d is described below
commit f5821b9d9d6143e9620a221a9da75819ea9d0cb5
Author: Sava Vranešević <20...@users.noreply.github.com>
AuthorDate: Thu Mar 20 10:48:30 2025 +0100
Support Duration in min/max agg functions (#15310)
* Support min/max agg functions on values of duration type
* Add tests for GROUP BY as well
---------
Co-authored-by: svranesevic <sv...@users.noreply.github.com>
Co-authored-by: Andrew Lamb <an...@nerdnetworks.org>
---
datafusion/functions-aggregate/src/min_max.rs | 36 +++++++++++++++++++++---
datafusion/sqllogictest/test_files/aggregate.slt | 32 +++++++++++++++++++++
2 files changed, 64 insertions(+), 4 deletions(-)
diff --git a/datafusion/functions-aggregate/src/min_max.rs b/datafusion/functions-aggregate/src/min_max.rs
index 83356e2f9f..17ac8c4301 100644
--- a/datafusion/functions-aggregate/src/min_max.rs
+++ b/datafusion/functions-aggregate/src/min_max.rs
@@ -22,8 +22,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,
@@ -518,6 +519,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!(
@@ -1597,7 +1625,7 @@ mod tests {
assert_eq!(
min_res,
ScalarValue::IntervalYearMonth(Some(IntervalYearMonthType::make_value(
- -2, 4
+ -2, 4,
)))
);
@@ -1609,7 +1637,7 @@ mod tests {
assert_eq!(
max_res,
ScalarValue::IntervalYearMonth(Some(IntervalYearMonthType::make_value(
- 5, 34
+ 5, 34,
)))
);
diff --git a/datafusion/sqllogictest/test_files/aggregate.slt b/datafusion/sqllogictest/test_files/aggregate.slt
index bc43f6bc8e..9598913f57 100644
--- a/datafusion/sqllogictest/test_files/aggregate.slt
+++ b/datafusion/sqllogictest/test_files/aggregate.slt
@@ -3807,6 +3807,38 @@ 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)'), 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;
+----
+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
+
+# 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
+drop table d;
+
# max_bool
statement ok
CREATE TABLE max_bool (value BOOLEAN);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org