@@ -24,10 +24,7 @@ use arrow::array::{
2424 PrimitiveBuilder , StringArray , StructArray , TimestampMicrosecondBuilder ,
2525} ;
2626use arrow:: compute:: can_cast_types;
27- use arrow:: datatypes:: {
28- i256, ArrowDictionaryKeyType , ArrowNativeType , DataType , Decimal256Type , GenericBinaryType ,
29- Schema ,
30- } ;
27+ use arrow:: datatypes:: { i256, ArrowDictionaryKeyType , ArrowNativeType , DataType , Decimal256Type , GenericBinaryType , Schema , TimeUnit } ;
3128use arrow:: {
3229 array:: {
3330 cast:: AsArray ,
@@ -964,9 +961,11 @@ fn cast_array(
964961 cast_options : & SparkCastOptions ,
965962) -> DataFusionResult < ArrayRef > {
966963 use DataType :: * ;
967- let array = array_with_timezone ( array, cast_options. timezone . clone ( ) , Some ( to_type) ) ?;
968964 let from_type = array. data_type ( ) . clone ( ) ;
969965
966+ let array = array_with_timezone ( array, cast_options. timezone . clone ( ) , Some ( to_type) ) ?;
967+ let eval_mode = cast_options. eval_mode ;
968+
970969 let native_cast_options: CastOptions = CastOptions {
971970 safe : !matches ! ( cast_options. eval_mode, EvalMode :: Ansi ) , // take safe mode from cast_options passed
972971 format_options : FormatOptions :: new ( )
@@ -1015,10 +1014,8 @@ fn cast_array(
10151014 }
10161015 }
10171016 } ;
1018- let from_type = array. data_type ( ) ;
1019- let eval_mode = cast_options. eval_mode ;
10201017
1021- let cast_result = match ( from_type, to_type) {
1018+ let cast_result = match ( & from_type, to_type) {
10221019 ( Utf8 , Boolean ) => spark_cast_utf8_to_boolean :: < i32 > ( & array, eval_mode) ,
10231020 ( LargeUtf8 , Boolean ) => spark_cast_utf8_to_boolean :: < i64 > ( & array, eval_mode) ,
10241021 ( Utf8 , Timestamp ( _, _) ) => {
@@ -1044,10 +1041,10 @@ fn cast_array(
10441041 | ( Int16 , Int8 )
10451042 if eval_mode != EvalMode :: Try =>
10461043 {
1047- spark_cast_int_to_int ( & array, eval_mode, from_type, to_type)
1044+ spark_cast_int_to_int ( & array, eval_mode, & from_type, to_type)
10481045 }
10491046 ( Int8 | Int16 | Int32 | Int64 , Decimal128 ( precision, scale) ) => {
1050- cast_int_to_decimal128 ( & array, eval_mode, from_type, to_type, * precision, * scale)
1047+ cast_int_to_decimal128 ( & array, eval_mode, & from_type, to_type, * precision, * scale)
10511048 }
10521049 ( Utf8 , Int8 | Int16 | Int32 | Int64 ) => {
10531050 cast_string_to_int :: < i32 > ( to_type, & array, eval_mode)
@@ -1079,19 +1076,19 @@ fn cast_array(
10791076 | ( Decimal128 ( _, _) , Int64 )
10801077 if eval_mode != EvalMode :: Try =>
10811078 {
1082- spark_cast_nonintegral_numeric_to_integral ( & array, eval_mode, from_type, to_type)
1079+ spark_cast_nonintegral_numeric_to_integral ( & array, eval_mode, & from_type, to_type)
10831080 }
10841081 ( Decimal128 ( _p, _s) , Boolean ) => spark_cast_decimal_to_boolean ( & array) ,
10851082 ( Utf8View , Utf8 ) => Ok ( cast_with_options ( & array, to_type, & CAST_OPTIONS ) ?) ,
10861083 ( Struct ( _) , Utf8 ) => Ok ( casts_struct_to_string ( array. as_struct ( ) , cast_options) ?) ,
10871084 ( Struct ( _) , Struct ( _) ) => Ok ( cast_struct_to_struct (
10881085 array. as_struct ( ) ,
1089- from_type,
1086+ & from_type,
10901087 to_type,
10911088 cast_options,
10921089 ) ?) ,
10931090 ( List ( _) , Utf8 ) => Ok ( cast_array_to_string ( array. as_list ( ) , cast_options) ?) ,
1094- ( List ( _) , List ( _) ) if can_cast_types ( from_type, to_type) => {
1091+ ( List ( _) , List ( _) ) if can_cast_types ( & from_type, to_type) => {
10951092 Ok ( cast_with_options ( & array, to_type, & CAST_OPTIONS ) ?)
10961093 }
10971094 ( UInt8 | UInt16 | UInt32 | UInt64 , Int8 | Int16 | Int32 | Int64 )
@@ -1102,7 +1099,7 @@ fn cast_array(
11021099 ( Binary , Utf8 ) => Ok ( cast_binary_to_string :: < i32 > ( & array, cast_options) ?) ,
11031100 ( Date32 , Timestamp ( _, tz) ) => Ok ( cast_date_to_timestamp ( & array, cast_options, tz) ?) ,
11041101 _ if cast_options. is_adapting_schema
1105- || is_datafusion_spark_compatible ( from_type, to_type) =>
1102+ || is_datafusion_spark_compatible ( & from_type, to_type) =>
11061103 {
11071104 // use DataFusion cast only when we know that it is compatible with Spark
11081105 Ok ( cast_with_options ( & array, to_type, & native_cast_options) ?)
@@ -1116,7 +1113,7 @@ fn cast_array(
11161113 ) ) )
11171114 }
11181115 } ;
1119- Ok ( spark_cast_postprocess ( cast_result?, from_type, to_type) )
1116+ Ok ( spark_cast_postprocess ( cast_result?, & from_type, to_type) )
11201117}
11211118
11221119fn cast_date_to_timestamp (
0 commit comments