@@ -2842,43 +2842,40 @@ fn literal_to_array_ref(
28422842 }
28432843 DataType :: List ( ref f) => {
28442844 let dt = f. data_type ( ) . clone ( ) ;
2845- let child_arrays : Vec < ArrayRef > = list_literal
2846- . list_values
2847- . iter ( )
2848- . map ( |c| literal_to_array_ref ( dt . clone ( ) , c . clone ( ) ) . unwrap ( ) )
2849- . collect ( ) ;
2850-
2851- // Convert Vec<ArrayRef> into Vec<&dyn Array> for concat()
2852- let child_refs : Vec < & dyn Array > =
2853- child_arrays . iter ( ) . map ( |a| a . as_ref ( ) ) . collect ( ) ;
2854-
2855- // --- Build offsets for the parent list ---
2856- let mut offsets = Vec :: with_capacity ( child_arrays . len ( ) + 1 ) ;
2857- offsets . push ( 0 ) ; // the first list always starts at 0
2858- let mut sum = 0 ;
2859- for arr in & child_arrays {
2860- sum += arr . len ( ) as i32 ; // each child's length adds to the total
2861- offsets . push ( sum ) ; // store cumulative sum as the next offset
2845+
2846+ // Build offsets and collect non-null child arrays
2847+ let mut offsets = Vec :: with_capacity ( list_literal . list_values . len ( ) + 1 ) ;
2848+ offsets . push ( 0i32 ) ;
2849+ let mut child_arrays : Vec < ArrayRef > = Vec :: new ( ) ;
2850+
2851+ for ( i , child_literal ) in list_literal . list_values . iter ( ) . enumerate ( ) {
2852+ if list_literal . null_mask [ i ] {
2853+ // Non-null entry: process the child array
2854+ let child_array = literal_to_array_ref ( dt . clone ( ) , child_literal . clone ( ) ) ? ;
2855+ let len = child_array . len ( ) as i32 ;
2856+ offsets . push ( offsets . last ( ) . unwrap ( ) + len ) ;
2857+ child_arrays . push ( child_array ) ;
2858+ } else {
2859+ // Null entry: just repeat the last offset (empty slot)
2860+ offsets . push ( * offsets . last ( ) . unwrap ( ) ) ;
2861+ }
28622862 }
28632863
2864- // Concatenate all child arrays' * values* into one array
2865- // Example: [[1,2,3], [4,5,6]] → values = [1,2,3,4,5,6]
2866- let output_array = if ! child_refs. is_empty ( ) {
2864+ // Concatenate all non-null child arrays' values into one array
2865+ let output_array = if !child_arrays . is_empty ( ) {
2866+ let child_refs: Vec < & dyn Array > = child_arrays . iter ( ) . map ( |a| a . as_ref ( ) ) . collect ( ) ;
28672867 arrow:: compute:: concat ( & child_refs) ?
28682868 } else {
2869- let x = new_empty_array ( & dt. clone ( ) ) ;
2870- offsets = vec ! [ x. offset( ) as i32 ] ;
2871- dbg ! ( & offsets) ;
2872- x
2869+ // All entries are null or the list is empty
2870+ new_empty_array ( & dt)
28732871 } ;
28742872
28752873 // Create and return the parent ListArray
28762874 Ok ( Arc :: new ( ListArray :: new (
2877- // Field: item type matches the concatenated child's type
28782875 FieldRef :: from ( Field :: new ( "item" , output_array. data_type ( ) . clone ( ) , true ) ) ,
28792876 OffsetBuffer :: new ( offsets. into ( ) ) ,
28802877 output_array,
2881- Some ( NullBuffer :: from ( list_literal. null_mask ) ) ,
2878+ Some ( NullBuffer :: from ( list_literal. null_mask . clone ( ) ) ) ,
28822879 ) ) )
28832880 }
28842881 dt => Err ( GeneralError ( format ! (
@@ -3704,12 +3701,14 @@ mod tests {
37043701 [1, 2, 3],
37053702 [4, 5, 6],
37063703 [7, 8, 9, null],
3704+ [],
37073705 null
37083706 ],
37093707 [
37103708 [10, null, 12]
37113709 ],
3712- null
3710+ null,
3711+ []
37133712 ]
37143713 */
37153714 let data = ListLiteral {
@@ -3750,11 +3749,14 @@ mod tests {
37503749 null_mask: vec![ true ] ,
37513750 ..Default :: default ( )
37523751 } ,
3753- // ListLiteral {
3754- // ..Default::default()
3755- // },
3752+ ListLiteral {
3753+ ..Default :: default ( )
3754+ } ,
3755+ ListLiteral {
3756+ ..Default :: default ( )
3757+ } ,
37563758 ] ,
3757- null_mask : vec ! [ true , true ] ,
3759+ null_mask : vec ! [ true , true , false , true ] ,
37583760 ..Default :: default ( )
37593761 } ;
37603762
@@ -3778,38 +3780,14 @@ mod tests {
37783780 true , // outer list nullable
37793781 ) ) ) ;
37803782
3781- // let data = ListLiteral {
3782- // list_values: vec![
3783- // ListLiteral {
3784- // int_values: vec![1, 2],
3785- // null_mask: vec![true, true],
3786- // ..Default::default()
3787- // },
3788- // ListLiteral {
3789- // ..Default::default()
3790- // }
3791- // ],
3792- // null_mask: vec![true, false],
3793- // ..Default::default()
3794- // };
3795- //
3796- // let nested_type = DataType::List(FieldRef::from(Field::new(
3797- // "item",
3798- // DataType::List(
3799- // Field::new("item", DataType::Int32, true).into(),
3800- // ), true)));
3801-
38023783 let array = literal_to_array_ref ( nested_type, data) ?;
38033784
38043785 dbg ! ( & array) ;
38053786 dbg ! ( & array. nulls( ) ) ;
38063787
3807-
3808-
3809-
38103788 // Top-level should be ListArray<ListArray<Int32>>
38113789 let list_outer = array. as_any ( ) . downcast_ref :: < ListArray > ( ) . unwrap ( ) ;
3812- assert_eq ! ( list_outer. len( ) , 2 ) ;
3790+ assert_eq ! ( list_outer. len( ) , 4 ) ;
38133791
38143792 // First outer element: ListArray<Int32>
38153793 let first_elem = list_outer. value ( 0 ) ;
0 commit comments