1818//! [`GroupValues`] trait for storing and interning group keys
1919
2020use arrow:: array:: types:: {
21- Date32Type , Date64Type , Decimal128Type , Time32MillisecondType , Time32SecondType ,
22- Time64MicrosecondType , Time64NanosecondType , TimestampMicrosecondType ,
23- TimestampMillisecondType , TimestampNanosecondType , TimestampSecondType ,
21+ Date32Type , Date64Type , Decimal128Type , Int8Type , Int16Type , Int32Type , Int64Type ,
22+ Time32MillisecondType , Time32SecondType , Time64MicrosecondType , Time64NanosecondType ,
23+ TimestampMicrosecondType , TimestampMillisecondType , TimestampNanosecondType ,
24+ TimestampSecondType , UInt8Type , UInt16Type , UInt32Type , UInt64Type ,
2425} ;
2526use arrow:: array:: { ArrayRef , downcast_primitive} ;
2627use arrow:: datatypes:: { DataType , SchemaRef , TimeUnit } ;
@@ -41,15 +42,15 @@ pub(crate) use single_group_by::primitive::HashValue;
4142use crate :: aggregates:: {
4243 group_values:: single_group_by:: {
4344 boolean:: GroupValuesBoolean , bytes:: GroupValuesBytes ,
44- bytes_view:: GroupValuesBytesView , primitive:: GroupValuesPrimitive ,
45+ bytes_view:: GroupValuesBytesView , dictionary:: GroupValuesDictionary ,
46+ primitive:: GroupValuesPrimitive ,
4547 } ,
4648 order:: GroupOrdering ,
4749} ;
4850
4951mod metrics;
50- mod null_builder;
51-
5252pub ( crate ) use metrics:: GroupByMetrics ;
53+ mod null_builder;
5354
5455/// Stores the group values during hash aggregation.
5556///
@@ -196,6 +197,45 @@ pub fn new_group_values(
196197 DataType :: Boolean => {
197198 return Ok ( Box :: new ( GroupValuesBoolean :: new ( ) ) ) ;
198199 }
200+ DataType :: Dictionary ( key_type, value_type) => {
201+ if supported_single_dictionary_value ( value_type) {
202+ return match key_type. as_ref ( ) {
203+ DataType :: Int8 => Ok ( Box :: new (
204+ GroupValuesDictionary :: < Int8Type > :: new ( value_type) ,
205+ ) ) ,
206+ DataType :: Int16 => Ok ( Box :: new (
207+ GroupValuesDictionary :: < Int16Type > :: new ( value_type) ,
208+ ) ) ,
209+ DataType :: Int32 => Ok ( Box :: new (
210+ GroupValuesDictionary :: < Int32Type > :: new ( value_type) ,
211+ ) ) ,
212+ DataType :: Int64 => Ok ( Box :: new (
213+ GroupValuesDictionary :: < Int64Type > :: new ( value_type) ,
214+ ) ) ,
215+ DataType :: UInt8 => Ok ( Box :: new (
216+ GroupValuesDictionary :: < UInt8Type > :: new ( value_type) ,
217+ ) ) ,
218+ DataType :: UInt16 => {
219+ Ok ( Box :: new ( GroupValuesDictionary :: < UInt16Type > :: new (
220+ value_type,
221+ ) ) )
222+ }
223+ DataType :: UInt32 => {
224+ Ok ( Box :: new ( GroupValuesDictionary :: < UInt32Type > :: new (
225+ value_type,
226+ ) ) )
227+ }
228+ DataType :: UInt64 => {
229+ Ok ( Box :: new ( GroupValuesDictionary :: < UInt64Type > :: new (
230+ value_type,
231+ ) ) )
232+ }
233+ _ => Err ( datafusion_common:: DataFusionError :: NotImplemented (
234+ format ! ( "Unsupported dictionary key type: {key_type:?}" ) ,
235+ ) ) ,
236+ } ;
237+ }
238+ }
199239 _ => { }
200240 }
201241 }
@@ -210,3 +250,18 @@ pub fn new_group_values(
210250 Ok ( Box :: new ( GroupValuesRows :: try_new ( schema) ?) )
211251 }
212252}
253+
254+ fn supported_single_dictionary_value ( t : & DataType ) -> bool {
255+ match t {
256+ DataType :: Utf8 | DataType :: LargeUtf8 | DataType :: Utf8View => true ,
257+ DataType :: List ( field)
258+ if matches ! (
259+ field. data_type( ) ,
260+ DataType :: Utf8 | DataType :: Utf8View | DataType :: LargeUtf8
261+ ) =>
262+ {
263+ true
264+ }
265+ _ => false ,
266+ }
267+ }
0 commit comments