Skip to content

Commit 90c35ca

Browse files
jonathanc-nalamb
authored andcommitted
feat: Add GroupColumn Decimal128Array (apache#13564)
* feat: Add GroupColumn `Decimal128Array * fix clippy * fix errors * remove .with_data_type * fix * fmt * remove adjust_output_array * fix * Add missing data type --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent 1003146 commit 90c35ca

File tree

5 files changed

+59
-7
lines changed

5 files changed

+59
-7
lines changed

datafusion/physical-plan/src/aggregates/group_values/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
use arrow::record_batch::RecordBatch;
2121
use arrow_array::types::{
22-
Date32Type, Date64Type, Time32MillisecondType, Time32SecondType,
22+
Date32Type, Date64Type, Decimal128Type, Time32MillisecondType, Time32SecondType,
2323
Time64MicrosecondType, Time64NanosecondType, TimestampMicrosecondType,
2424
TimestampMillisecondType, TimestampNanosecondType, TimestampSecondType,
2525
};
@@ -170,6 +170,9 @@ pub(crate) fn new_group_values(
170170
TimeUnit::Microsecond => downcast_helper!(TimestampMicrosecondType, d),
171171
TimeUnit::Nanosecond => downcast_helper!(TimestampNanosecondType, d),
172172
},
173+
DataType::Decimal128(_, _) => {
174+
downcast_helper!(Decimal128Type, d);
175+
}
173176
DataType::Utf8 => {
174177
return Ok(Box::new(GroupValuesByes::<i32>::new(OutputType::Utf8)));
175178
}

datafusion/physical-plan/src/aggregates/group_values/multi_group_by/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ use crate::aggregates::group_values::GroupValues;
3131
use ahash::RandomState;
3232
use arrow::compute::cast;
3333
use arrow::datatypes::{
34-
BinaryViewType, Date32Type, Date64Type, Float32Type, Float64Type, Int16Type,
35-
Int32Type, Int64Type, Int8Type, StringViewType, Time32MillisecondType,
34+
BinaryViewType, Date32Type, Date64Type, Decimal128Type, Float32Type, Float64Type,
35+
Int16Type, Int32Type, Int64Type, Int8Type, StringViewType, Time32MillisecondType,
3636
Time32SecondType, Time64MicrosecondType, Time64NanosecondType,
3737
TimestampMicrosecondType, TimestampMillisecondType, TimestampNanosecondType,
3838
TimestampSecondType, UInt16Type, UInt32Type, UInt64Type, UInt8Type,
@@ -1008,6 +1008,14 @@ impl<const STREAMING: bool> GroupValues for GroupValuesColumn<STREAMING> {
10081008
)
10091009
}
10101010
},
1011+
&DataType::Decimal128(_, _) => {
1012+
instantiate_primitive! {
1013+
v,
1014+
nullable,
1015+
Decimal128Type,
1016+
data_type
1017+
}
1018+
}
10111019
&DataType::Utf8 => {
10121020
let b = ByteGroupValueBuilder::<i32>::new(OutputType::Utf8);
10131021
v.push(Box::new(b) as _)
@@ -1214,6 +1222,7 @@ fn supported_type(data_type: &DataType) -> bool {
12141222
| DataType::UInt64
12151223
| DataType::Float32
12161224
| DataType::Float64
1225+
| DataType::Decimal128(_, _)
12171226
| DataType::Utf8
12181227
| DataType::LargeUtf8
12191228
| DataType::Binary

datafusion/physical-plan/src/aggregates/group_values/multi_group_by/primitive.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ impl<T: ArrowPrimitiveType, const NULLABLE: bool> GroupColumn
200200

201201
let first_n_nulls = if NULLABLE { self.nulls.take_n(n) } else { None };
202202

203-
Arc::new(PrimitiveArray::<T>::new(
204-
ScalarBuffer::from(first_n),
205-
first_n_nulls,
206-
))
203+
Arc::new(
204+
PrimitiveArray::<T>::new(ScalarBuffer::from(first_n), first_n_nulls)
205+
.with_data_type(self.data_type.clone()),
206+
)
207207
}
208208
}
209209

datafusion/physical-plan/src/aggregates/group_values/single_group_by/primitive.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ where
208208
build_primitive(split, null_group)
209209
}
210210
};
211+
211212
Ok(vec![Arc::new(array.with_data_type(self.data_type.clone()))])
212213
}
213214

datafusion/sqllogictest/test_files/group_by.slt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5499,3 +5499,42 @@ SELECT
54995499
GROUP BY ts, text
55005500
----
55015501
foo 2024-01-01T08:00:00+08:00
5502+
5503+
# Test multi group by int + Decimal128
5504+
statement ok
5505+
create table source as values
5506+
(1, '123.45'),
5507+
(1, '123.45'),
5508+
(2, '678.90'),
5509+
(2, '1011.12'),
5510+
(3, '1314.15'),
5511+
(3, '1314.15'),
5512+
(2, '1011.12'),
5513+
(null, null),
5514+
(null, '123.45'),
5515+
(null, null),
5516+
(null, '123.45'),
5517+
(2, '678.90'),
5518+
(2, '678.90'),
5519+
(1, null)
5520+
;
5521+
5522+
statement ok
5523+
create view t as select column1 as a, arrow_cast(column2, 'Decimal128(10, 2)') as b from source;
5524+
5525+
query IRI
5526+
select a, b, count(*) from t group by a, b order by a, b;
5527+
----
5528+
1 123.45 2
5529+
1 NULL 1
5530+
2 678.9 3
5531+
2 1011.12 2
5532+
3 1314.15 2
5533+
NULL 123.45 2
5534+
NULL NULL 2
5535+
5536+
statement ok
5537+
drop view t
5538+
5539+
statement ok
5540+
drop table source;

0 commit comments

Comments
 (0)