@@ -89,7 +89,7 @@ use arrow::array::{
89
89
Float64Array , Int16Array , Int32Array , Int64Array , Int8Array , ListArray , NullArray ,
90
90
StringBuilder , TimestampMicrosecondArray ,
91
91
} ;
92
- use arrow:: buffer:: { BooleanBuffer , OffsetBuffer } ;
92
+ use arrow:: buffer:: { BooleanBuffer , NullBuffer , OffsetBuffer } ;
93
93
use datafusion:: common:: utils:: SingleRowListArrayBuilder ;
94
94
use datafusion:: physical_plan:: coalesce_batches:: CoalesceBatchesExec ;
95
95
use datafusion:: physical_plan:: filter:: FilterExec ;
@@ -484,10 +484,8 @@ impl PhysicalPlanner {
484
484
}
485
485
} ,
486
486
Value :: ListVal ( values) => {
487
- dbg ! ( & values) ;
488
-
489
- if let DataType :: List ( f) = data_type {
490
- SingleRowListArrayBuilder :: new ( literal_to_array_ref ( f. data_type ( ) . clone ( ) , values. clone ( ) ) ?) . build_list_scalar ( )
487
+ if let DataType :: List ( ref f) = data_type {
488
+ SingleRowListArrayBuilder :: new ( literal_to_array_ref ( data_type, values. clone ( ) ) ?) . build_list_scalar ( )
491
489
} else {
492
490
return Err ( GeneralError ( format ! (
493
491
"Expected DataType::List but got {data_type:?}"
@@ -2826,29 +2824,29 @@ fn literal_to_array_ref(
2826
2824
. collect ( ) ;
2827
2825
2828
2826
// Convert Vec<ArrayRef> into Vec<&dyn Array> for concat()
2829
- let child_refs: Vec < & dyn arrow :: array :: Array > =
2827
+ let child_refs: Vec < & dyn Array > =
2830
2828
child_arrays. iter ( ) . map ( |a| a. as_ref ( ) ) . collect ( ) ;
2831
2829
2832
- // Concatenate all child arrays' *values* into one array
2833
- // Example: [[1,2,3], [4,5,6]] → values = [1,2,3,4,5,6]
2834
- let concat = arrow:: compute:: concat ( & child_refs) . unwrap ( ) ;
2835
-
2836
2830
// --- Build offsets for the parent list ---
2837
2831
let mut offsets = Vec :: with_capacity ( child_arrays. len ( ) + 1 ) ;
2838
- offsets. push ( 0 ) ; // first list always starts at 0
2832
+ offsets. push ( 0 ) ; // the first list always starts at 0
2839
2833
let mut sum = 0 ;
2840
2834
for arr in & child_arrays {
2841
- sum += arr. len ( ) as i32 ; // each child's length adds to total
2842
- offsets. push ( sum) ; // store cumulative sum as next offset
2835
+ sum += arr. len ( ) as i32 ; // each child's length adds to the total
2836
+ offsets. push ( sum) ; // store cumulative sum as the next offset
2843
2837
}
2844
2838
2839
+ // Concatenate all child arrays' *values* into one array
2840
+ // Example: [[1,2,3], [4,5,6]] → values = [1,2,3,4,5,6]
2841
+ let concat = arrow:: compute:: concat ( & child_refs) ?;
2842
+
2845
2843
// Create and return the parent ListArray
2846
2844
Ok ( Arc :: new ( ListArray :: new (
2847
2845
// Field: item type matches the concatenated child's type
2848
2846
FieldRef :: from ( Field :: new ( "item" , concat. data_type ( ) . clone ( ) , true ) ) ,
2849
- OffsetBuffer :: new ( offsets. into ( ) ) , // where each sublist starts/ends
2850
- concat, // the flattened values array
2851
- None , // no null bitmap at this level
2847
+ OffsetBuffer :: new ( offsets. into ( ) ) ,
2848
+ concat,
2849
+ Some ( NullBuffer :: from ( list_literal . null_mask ) ) ,
2852
2850
) ) )
2853
2851
}
2854
2852
dt => Err ( GeneralError ( format ! (
@@ -3701,8 +3699,11 @@ mod tests {
3701
3699
ListLiteral {
3702
3700
..Default :: default ( )
3703
3701
} ,
3702
+ ListLiteral {
3703
+ ..Default :: default ( )
3704
+ } ,
3704
3705
] ,
3705
- null_mask: vec![ true , true , true , false ] ,
3706
+ null_mask: vec![ true , true , true , false , true ] ,
3706
3707
..Default :: default ( )
3707
3708
} ,
3708
3709
ListLiteral {
@@ -3714,11 +3715,11 @@ mod tests {
3714
3715
null_mask: vec![ true ] ,
3715
3716
..Default :: default ( )
3716
3717
} ,
3717
- ListLiteral {
3718
- ..Default :: default ( )
3719
- } ,
3718
+ // ListLiteral {
3719
+ // ..Default::default()
3720
+ // },
3720
3721
] ,
3721
- null_mask : vec ! [ true , true , false ] ,
3722
+ null_mask : vec ! [ true , true ] ,
3722
3723
..Default :: default ( )
3723
3724
} ;
3724
3725
@@ -3742,8 +3743,35 @@ mod tests {
3742
3743
true , // outer list nullable
3743
3744
) ) ) ;
3744
3745
3746
+ let data = ListLiteral {
3747
+ list_values : vec ! [
3748
+ ListLiteral {
3749
+ int_values: vec![ 1 , 2 ] ,
3750
+ null_mask: vec![ true , true ] ,
3751
+ ..Default :: default ( )
3752
+ } ,
3753
+ ListLiteral {
3754
+ ..Default :: default ( )
3755
+ }
3756
+ ] ,
3757
+ null_mask : vec ! [ true , false ] ,
3758
+ ..Default :: default ( )
3759
+ } ;
3760
+
3761
+ let nested_type = DataType :: List ( FieldRef :: from ( Field :: new (
3762
+ "item" ,
3763
+ DataType :: List (
3764
+ Field :: new ( "item" , DataType :: Int32 , true ) . into ( ) ,
3765
+ ) , true ) ) ) ;
3766
+
3745
3767
let array = literal_to_array_ref ( nested_type, data) ?;
3746
3768
3769
+ dbg ! ( & array) ;
3770
+ dbg ! ( & array. nulls( ) ) ;
3771
+
3772
+
3773
+
3774
+
3747
3775
// Top-level should be ListArray<ListArray<Int32>>
3748
3776
let list_outer = array. as_any ( ) . downcast_ref :: < ListArray > ( ) . unwrap ( ) ;
3749
3777
assert_eq ! ( list_outer. len( ) , 2 ) ;
@@ -3752,7 +3780,7 @@ mod tests {
3752
3780
let first_elem = list_outer. value ( 0 ) ;
3753
3781
dbg ! ( & first_elem) ;
3754
3782
let list_inner = first_elem. as_any ( ) . downcast_ref :: < ListArray > ( ) . unwrap ( ) ;
3755
- assert_eq ! ( list_inner. len( ) , 4 ) ;
3783
+ assert_eq ! ( list_inner. len( ) , 5 ) ;
3756
3784
3757
3785
// Inner values
3758
3786
let v0 = list_inner. value ( 0 ) ;
0 commit comments