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 cafe0e7ba3 GroupsAccumulator for Duration (#15322)
cafe0e7ba3 is described below
commit cafe0e7ba3f254af7f9e0149ae2aacb7a43bbad8
Author: Shruti Sharma <[email protected]>
AuthorDate: Sat Mar 22 00:40:36 2025 +0530
GroupsAccumulator for Duration (#15322)
---
datafusion/functions-aggregate/src/min_max.rs | 33 +++++++++++++++++++++---
datafusion/sqllogictest/test_files/aggregate.slt | 14 ++++++++++
2 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/datafusion/functions-aggregate/src/min_max.rs
b/datafusion/functions-aggregate/src/min_max.rs
index 17ac8c4301..ea4cad5488 100644
--- a/datafusion/functions-aggregate/src/min_max.rs
+++ b/datafusion/functions-aggregate/src/min_max.rs
@@ -33,9 +33,10 @@ use arrow::array::{
};
use arrow::compute;
use arrow::datatypes::{
- DataType, Decimal128Type, Decimal256Type, Float16Type, Float32Type,
Float64Type,
- Int16Type, Int32Type, Int64Type, Int8Type, IntervalUnit, UInt16Type,
UInt32Type,
- UInt64Type, UInt8Type,
+ DataType, Decimal128Type, Decimal256Type, DurationMicrosecondType,
+ DurationMillisecondType, DurationNanosecondType, DurationSecondType,
Float16Type,
+ Float32Type, Float64Type, Int16Type, Int32Type, Int64Type, Int8Type,
IntervalUnit,
+ UInt16Type, UInt32Type, UInt64Type, UInt8Type,
};
use datafusion_common::stats::Precision;
use datafusion_common::{
@@ -264,6 +265,7 @@ impl AggregateUDFImpl for Max {
| Binary
| LargeBinary
| BinaryView
+ | Duration(_)
)
}
@@ -318,6 +320,18 @@ impl AggregateUDFImpl for Max {
Timestamp(Nanosecond, _) => {
primitive_max_accumulator!(data_type, i64,
TimestampNanosecondType)
}
+ Duration(Second) => {
+ primitive_max_accumulator!(data_type, i64, DurationSecondType)
+ }
+ Duration(Millisecond) => {
+ primitive_max_accumulator!(data_type, i64,
DurationMillisecondType)
+ }
+ Duration(Microsecond) => {
+ primitive_max_accumulator!(data_type, i64,
DurationMicrosecondType)
+ }
+ Duration(Nanosecond) => {
+ primitive_max_accumulator!(data_type, i64,
DurationNanosecondType)
+ }
Decimal128(_, _) => {
primitive_max_accumulator!(data_type, i128, Decimal128Type)
}
@@ -1118,6 +1132,7 @@ impl AggregateUDFImpl for Min {
| Binary
| LargeBinary
| BinaryView
+ | Duration(_)
)
}
@@ -1172,6 +1187,18 @@ impl AggregateUDFImpl for Min {
Timestamp(Nanosecond, _) => {
primitive_min_accumulator!(data_type, i64,
TimestampNanosecondType)
}
+ Duration(Second) => {
+ primitive_min_accumulator!(data_type, i64, DurationSecondType)
+ }
+ Duration(Millisecond) => {
+ primitive_min_accumulator!(data_type, i64,
DurationMillisecondType)
+ }
+ Duration(Microsecond) => {
+ primitive_min_accumulator!(data_type, i64,
DurationMicrosecondType)
+ }
+ Duration(Nanosecond) => {
+ primitive_min_accumulator!(data_type, i64,
DurationNanosecondType)
+ }
Decimal128(_, _) => {
primitive_min_accumulator!(data_type, i128, Decimal128Type)
}
diff --git a/datafusion/sqllogictest/test_files/aggregate.slt
b/datafusion/sqllogictest/test_files/aggregate.slt
index 9598913f57..9d8620b100 100644
--- a/datafusion/sqllogictest/test_files/aggregate.slt
+++ b/datafusion/sqllogictest/test_files/aggregate.slt
@@ -3835,6 +3835,20 @@ SELECT max(column1), max(column2), max(column3),
max(column4), column5 FROM d GR
----
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;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]