@@ -23,7 +23,11 @@ use arrow::array::types::{
2323 TimestampMillisecondType , TimestampNanosecondType , TimestampSecondType ,
2424} ;
2525use arrow:: array:: { ArrayRef , downcast_primitive} ;
26- use arrow:: datatypes:: { DataType , SchemaRef , TimeUnit } ;
26+
27+ use arrow:: datatypes:: {
28+ DataType , Int8Type , Int16Type , Int32Type , Int64Type , SchemaRef , TimeUnit , UInt8Type ,
29+ UInt16Type , UInt32Type , UInt64Type ,
30+ } ;
2731use datafusion_common:: Result ;
2832
2933use datafusion_expr:: EmitTo ;
@@ -36,7 +40,9 @@ use datafusion_physical_expr::binary_map::OutputType;
3640use multi_group_by:: GroupValuesColumn ;
3741use row:: GroupValuesRows ;
3842
39- pub ( crate ) use single_group_by:: primitive:: HashValue ;
43+ pub ( crate ) use single_group_by:: {
44+ dictionary:: GroupValuesDictionary , primitive:: HashValue ,
45+ } ;
4046
4147use crate :: aggregates:: {
4248 group_values:: single_group_by:: {
@@ -196,6 +202,45 @@ pub fn new_group_values(
196202 DataType :: Boolean => {
197203 return Ok ( Box :: new ( GroupValuesBoolean :: new ( ) ) ) ;
198204 }
205+ DataType :: Dictionary ( key_type, value_type) => {
206+ if supported_single_dictionary_value ( value_type) {
207+ return match key_type. as_ref ( ) {
208+ DataType :: Int8 => Ok ( Box :: new (
209+ GroupValuesDictionary :: < Int8Type > :: new ( value_type) ,
210+ ) ) ,
211+ DataType :: Int16 => Ok ( Box :: new (
212+ GroupValuesDictionary :: < Int16Type > :: new ( value_type) ,
213+ ) ) ,
214+ DataType :: Int32 => Ok ( Box :: new (
215+ GroupValuesDictionary :: < Int32Type > :: new ( value_type) ,
216+ ) ) ,
217+ DataType :: Int64 => Ok ( Box :: new (
218+ GroupValuesDictionary :: < Int64Type > :: new ( value_type) ,
219+ ) ) ,
220+ DataType :: UInt8 => Ok ( Box :: new (
221+ GroupValuesDictionary :: < UInt8Type > :: new ( value_type) ,
222+ ) ) ,
223+ DataType :: UInt16 => {
224+ Ok ( Box :: new ( GroupValuesDictionary :: < UInt16Type > :: new (
225+ value_type,
226+ ) ) )
227+ }
228+ DataType :: UInt32 => {
229+ Ok ( Box :: new ( GroupValuesDictionary :: < UInt32Type > :: new (
230+ value_type,
231+ ) ) )
232+ }
233+ DataType :: UInt64 => {
234+ Ok ( Box :: new ( GroupValuesDictionary :: < UInt64Type > :: new (
235+ value_type,
236+ ) ) )
237+ }
238+ _ => Err ( datafusion_common:: DataFusionError :: NotImplemented (
239+ format ! ( "Unsupported dictionary key type: {key_type:?}" ) ,
240+ ) ) ,
241+ } ;
242+ }
243+ }
199244 _ => { }
200245 }
201246 }
@@ -210,3 +255,18 @@ pub fn new_group_values(
210255 Ok ( Box :: new ( GroupValuesRows :: try_new ( schema) ?) )
211256 }
212257}
258+
259+ fn supported_single_dictionary_value ( t : & DataType ) -> bool {
260+ match t {
261+ DataType :: Utf8 | DataType :: LargeUtf8 | DataType :: Utf8View => true ,
262+ DataType :: List ( field)
263+ if matches ! (
264+ field. data_type( ) ,
265+ DataType :: Utf8 | DataType :: Utf8View | DataType :: LargeUtf8
266+ ) =>
267+ {
268+ true
269+ }
270+ _ => false ,
271+ }
272+ }
0 commit comments