@@ -33,7 +33,11 @@ use arrow::{
3333 util:: display:: FormatOptions ,
3434} ;
3535use arrow_array:: {
36- types:: { Date32Type , Int16Type , Int32Type , Int64Type , Int8Type } , Array , ArrayRef , BooleanArray , Decimal128Array , DictionaryArray , Float32Array , Float64Array , GenericStringArray , Int16Array , Int32Array , Int64Array , Int8Array , OffsetSizeTrait , PrimitiveArray
36+ make_array,
37+ types:: { Date32Type , Int16Type , Int32Type , Int64Type , Int8Type } ,
38+ Array , ArrayRef , BooleanArray , Decimal128Array , DictionaryArray , Float32Array , Float64Array ,
39+ GenericStringArray , Int16Array , Int32Array , Int64Array , Int8Array , OffsetSizeTrait ,
40+ PrimitiveArray ,
3741} ;
3842use arrow_schema:: { DataType , Schema } ;
3943use chrono:: { NaiveDate , NaiveDateTime , TimeZone , Timelike } ;
@@ -508,21 +512,11 @@ impl Cast {
508512 . downcast_ref :: < DictionaryArray < Int32Type > > ( )
509513 . expect ( "Expected a dictionary array" ) ;
510514
511- // cast dictionary values directly
512- let casted_dictionary = DictionaryArray :: < Int32Type > :: new (
513- dict_array . keys ( ) . clone ( ) ,
514- self . cast_array ( dict_array . values ( ) . clone ( ) ) ? ,
515+ let casted_result = make_array (
516+ self . cast_array ( dict_array . values ( ) . clone ( ) ) ?
517+ . to_data ( )
518+ . clone ( ) ,
515519 ) ;
516-
517- let casted_result = match to_type {
518- DataType :: Dictionary ( _, _) => Arc :: new ( casted_dictionary) ,
519- _ => cast_with_options (
520- & casted_dictionary,
521- & casted_dictionary. value_type ( ) ,
522- & CAST_OPTIONS ,
523- ) ?
524- } ;
525-
526520 return Ok ( spark_cast ( casted_result, & from_type, to_type) ) ;
527521 }
528522 _ => array,
@@ -1749,10 +1743,7 @@ mod tests {
17491743 let result = cast. cast_array ( dict_array) ?;
17501744 assert_eq ! (
17511745 * result. data_type( ) ,
1752- DataType :: Timestamp (
1753- TimeUnit :: Microsecond ,
1754- Some ( timezone. into( ) )
1755- )
1746+ DataType :: Timestamp ( TimeUnit :: Microsecond , Some ( timezone. into( ) ) )
17561747 ) ;
17571748 assert_eq ! ( result. len( ) , 2 ) ;
17581749
0 commit comments