@@ -40,7 +40,9 @@ use crate::cast::{
40
40
use crate :: error:: { DataFusionError , Result , _exec_err, _internal_err, _not_impl_err} ;
41
41
use crate :: hash_utils:: create_hashes;
42
42
use crate :: utils:: {
43
- array_into_fixed_size_list_array, array_into_large_list_array, array_into_list_array,
43
+ array_into_fixed_size_list_array_with_field_name, array_into_large_list_array,
44
+ array_into_large_list_array_with_field_name, array_into_list_array,
45
+ array_into_list_array_with_field_name,
44
46
} ;
45
47
use arrow:: compute:: kernels:: numeric:: * ;
46
48
use arrow:: util:: display:: { array_value_to_string, ArrayFormatter , FormatOptions } ;
@@ -2663,27 +2665,36 @@ impl ScalarValue {
2663
2665
let list_array = array. as_list :: < i32 > ( ) ;
2664
2666
let nested_array = list_array. value ( index) ;
2665
2667
// Produces a single element `ListArray` with the value at `index`.
2666
- let arr =
2667
- Arc :: new ( array_into_list_array ( nested_array, field. is_nullable ( ) ) ) ;
2668
+ let arr = Arc :: new ( array_into_list_array_with_field_name (
2669
+ nested_array,
2670
+ field. is_nullable ( ) ,
2671
+ field. name ( ) ,
2672
+ ) ) ;
2668
2673
2669
2674
ScalarValue :: List ( arr)
2670
2675
}
2671
- DataType :: LargeList ( _ ) => {
2676
+ DataType :: LargeList ( field ) => {
2672
2677
let list_array = as_large_list_array ( array) ;
2673
2678
let nested_array = list_array. value ( index) ;
2674
2679
// Produces a single element `LargeListArray` with the value at `index`.
2675
- let arr = Arc :: new ( array_into_large_list_array ( nested_array) ) ;
2680
+ let arr = Arc :: new ( array_into_large_list_array_with_field_name (
2681
+ nested_array,
2682
+ field. name ( ) ,
2683
+ ) ) ;
2676
2684
2677
2685
ScalarValue :: LargeList ( arr)
2678
2686
}
2679
2687
// TODO: There is no test for FixedSizeList now, add it later
2680
- DataType :: FixedSizeList ( _ , _) => {
2688
+ DataType :: FixedSizeList ( field , _) => {
2681
2689
let list_array = as_fixed_size_list_array ( array) ?;
2682
2690
let nested_array = list_array. value ( index) ;
2683
2691
// Produces a single element `ListArray` with the value at `index`.
2684
2692
let list_size = nested_array. len ( ) ;
2685
- let arr =
2686
- Arc :: new ( array_into_fixed_size_list_array ( nested_array, list_size) ) ;
2693
+ let arr = Arc :: new ( array_into_fixed_size_list_array_with_field_name (
2694
+ nested_array,
2695
+ list_size,
2696
+ field. name ( ) ,
2697
+ ) ) ;
2687
2698
2688
2699
ScalarValue :: FixedSizeList ( arr)
2689
2700
}
@@ -5970,6 +5981,51 @@ mod tests {
5970
5981
ScalarValue :: from ( "larger than 12 bytes string" ) ,
5971
5982
DataType :: Utf8View ,
5972
5983
) ;
5984
+ check_scalar_cast (
5985
+ {
5986
+ let element_field =
5987
+ Arc :: new ( Field :: new ( "element" , DataType :: Int32 , true ) ) ;
5988
+
5989
+ let mut builder =
5990
+ ListBuilder :: new ( Int32Builder :: new ( ) ) . with_field ( element_field) ;
5991
+ builder. append_value ( [ Some ( 1 ) ] ) ;
5992
+ builder. append ( true ) ;
5993
+
5994
+ ScalarValue :: List ( Arc :: new ( builder. finish ( ) ) )
5995
+ } ,
5996
+ DataType :: List ( Arc :: new ( Field :: new ( "element" , DataType :: Int64 , true ) ) ) ,
5997
+ ) ;
5998
+ check_scalar_cast (
5999
+ {
6000
+ let element_field =
6001
+ Arc :: new ( Field :: new ( "element" , DataType :: Int32 , true ) ) ;
6002
+
6003
+ let mut builder = FixedSizeListBuilder :: new ( Int32Builder :: new ( ) , 1 )
6004
+ . with_field ( element_field) ;
6005
+ builder. values ( ) . append_value ( 1 ) ;
6006
+ builder. append ( true ) ;
6007
+
6008
+ ScalarValue :: FixedSizeList ( Arc :: new ( builder. finish ( ) ) )
6009
+ } ,
6010
+ DataType :: FixedSizeList (
6011
+ Arc :: new ( Field :: new ( "element" , DataType :: Int64 , true ) ) ,
6012
+ 1 ,
6013
+ ) ,
6014
+ ) ;
6015
+ check_scalar_cast (
6016
+ {
6017
+ let element_field =
6018
+ Arc :: new ( Field :: new ( "element" , DataType :: Int32 , true ) ) ;
6019
+
6020
+ let mut builder =
6021
+ LargeListBuilder :: new ( Int32Builder :: new ( ) ) . with_field ( element_field) ;
6022
+ builder. append_value ( [ Some ( 1 ) ] ) ;
6023
+ builder. append ( true ) ;
6024
+
6025
+ ScalarValue :: LargeList ( Arc :: new ( builder. finish ( ) ) )
6026
+ } ,
6027
+ DataType :: LargeList ( Arc :: new ( Field :: new ( "element" , DataType :: Int64 , true ) ) ) ,
6028
+ ) ;
5973
6029
}
5974
6030
5975
6031
// mimics how casting work on scalar values by `casting` `scalar` to `desired_type`
0 commit comments