@@ -19,16 +19,20 @@ use std::any::Any;
1919use std:: sync:: Arc ;
2020
2121use arrow:: array:: {
22- Array , BooleanArray , Capacities , MutableArrayData , Scalar , make_array ,
23- make_comparator,
22+ Array , BooleanArray , Capacities , DictionaryArray , MutableArrayData , Scalar ,
23+ make_array , make_comparator,
2424} ;
2525use arrow:: compute:: SortOptions ;
26- use arrow:: datatypes:: { DataType , Field , FieldRef } ;
26+ use arrow:: datatypes:: {
27+ DataType , Field , FieldRef , Int8Type , Int16Type , Int32Type , Int64Type , UInt8Type ,
28+ UInt16Type , UInt32Type , UInt64Type ,
29+ } ;
2730use arrow_buffer:: NullBuffer ;
2831
2932use datafusion_common:: cast:: { as_map_array, as_struct_array} ;
3033use datafusion_common:: {
31- Result , ScalarValue , exec_err, internal_err, plan_datafusion_err,
34+ Result , ScalarValue , exec_datafusion_err, exec_err, internal_datafusion_err,
35+ internal_err, plan_datafusion_err,
3236} ;
3337use datafusion_expr:: expr:: ScalarFunction ;
3438use datafusion_expr:: simplify:: ExprSimplifyResult ;
@@ -211,22 +215,21 @@ fn extract_single_field(base: ColumnarValue, name: ScalarValue) -> Result<Column
211215 ( $key_ty: ty) => { {
212216 let dict = array
213217 . as_any( )
214- . downcast_ref:: <arrow :: array :: DictionaryArray <$key_ty>>( )
218+ . downcast_ref:: <DictionaryArray <$key_ty>>( )
215219 . ok_or_else( || {
216- datafusion_common:: DataFusionError :: Internal ( format!(
217- "Failed to downcast dictionary with key type {}" ,
218- key_type
219- ) )
220+ internal_datafusion_err!(
221+ "Failed to downcast dictionary with key type {key_type}"
222+ )
220223 } ) ?;
221224 let values_struct = as_struct_array( dict. values( ) ) ?;
222225 let field_col =
223226 values_struct. column_by_name( & field_name) . ok_or_else( || {
224- datafusion_common :: DataFusionError :: Execution ( format !(
227+ exec_datafusion_err !(
225228 "Field {field_name} not found in dictionary struct"
226- ) )
229+ )
227230 } ) ?;
228231 // Rebuild dictionary: same keys, extracted field as values.
229- let new_dict = arrow :: array :: DictionaryArray :: <$key_ty>:: try_new(
232+ let new_dict = DictionaryArray :: <$key_ty>:: try_new(
230233 dict. keys( ) . clone( ) ,
231234 Arc :: clone( field_col) ,
232235 ) ?;
@@ -235,14 +238,14 @@ fn extract_single_field(base: ColumnarValue, name: ScalarValue) -> Result<Column
235238 }
236239
237240 match key_type. as_ref ( ) {
238- DataType :: Int8 => extract_dict_field ! ( arrow :: datatypes :: Int8Type ) ,
239- DataType :: Int16 => extract_dict_field ! ( arrow :: datatypes :: Int16Type ) ,
240- DataType :: Int32 => extract_dict_field ! ( arrow :: datatypes :: Int32Type ) ,
241- DataType :: Int64 => extract_dict_field ! ( arrow :: datatypes :: Int64Type ) ,
242- DataType :: UInt8 => extract_dict_field ! ( arrow :: datatypes :: UInt8Type ) ,
243- DataType :: UInt16 => extract_dict_field ! ( arrow :: datatypes :: UInt16Type ) ,
244- DataType :: UInt32 => extract_dict_field ! ( arrow :: datatypes :: UInt32Type ) ,
245- DataType :: UInt64 => extract_dict_field ! ( arrow :: datatypes :: UInt64Type ) ,
241+ DataType :: Int8 => extract_dict_field ! ( Int8Type ) ,
242+ DataType :: Int16 => extract_dict_field ! ( Int16Type ) ,
243+ DataType :: Int32 => extract_dict_field ! ( Int32Type ) ,
244+ DataType :: Int64 => extract_dict_field ! ( Int64Type ) ,
245+ DataType :: UInt8 => extract_dict_field ! ( UInt8Type ) ,
246+ DataType :: UInt16 => extract_dict_field ! ( UInt16Type ) ,
247+ DataType :: UInt32 => extract_dict_field ! ( UInt32Type ) ,
248+ DataType :: UInt64 => extract_dict_field ! ( UInt64Type ) ,
246249 other => exec_err ! ( "Unsupported dictionary key type: {other}" ) ,
247250 }
248251 }
@@ -400,9 +403,7 @@ impl ScalarUDFImpl for GetFieldFunc {
400403 sv. try_as_str ( ) . flatten ( ) . filter ( |s| !s. is_empty ( ) )
401404 } )
402405 . ok_or_else ( || {
403- datafusion_common:: DataFusionError :: Execution (
404- "Field name must be a non-empty string" . to_string ( ) ,
405- )
406+ exec_datafusion_err ! ( "Field name must be a non-empty string" )
406407 } ) ?;
407408
408409 let child_field = fields
0 commit comments