@@ -818,7 +818,10 @@ impl ArrayLevels {
818818
819819 // Select the non-null indices for this chunk.
820820 let nni = & self . non_null_indices [ chunk. value_offset ..chunk. value_offset + chunk. num_values ] ;
821- // Compute the array range spanned by the non-null indices
821+ // Compute the array range spanned by the non-null indices.
822+ // When nni is empty (all-null chunk), start=0, end=0 → zero-length
823+ // array slice; write_batch_internal will process only the def/rep
824+ // levels and write no values.
822825 let start = nni. first ( ) . copied ( ) . unwrap_or ( 0 ) ;
823826 let end = nni. last ( ) . map_or ( 0 , |& i| i + 1 ) ;
824827 // Shift indices to be relative to the sliced array.
@@ -2270,4 +2273,30 @@ mod tests {
22702273 assert_eq ! ( chunk2. non_null_indices, vec![ 0 , 1 ] ) ;
22712274 assert_eq ! ( chunk2. array. len( ) , 2 ) ;
22722275 }
2276+
2277+ #[ test]
2278+ fn test_slice_for_chunk_all_null ( ) {
2279+ // All-null chunk: num_values=0 → empty nni slice → zero-length array.
2280+ let array: ArrayRef = Arc :: new ( Int32Array :: from ( vec ! [ Some ( 1 ) , None , None , Some ( 4 ) ] ) ) ;
2281+ let logical_nulls = array. logical_nulls ( ) ;
2282+ let levels = ArrayLevels {
2283+ def_levels : Some ( vec ! [ 1 , 0 , 0 , 1 ] ) ,
2284+ rep_levels : None ,
2285+ non_null_indices : vec ! [ 0 , 3 ] ,
2286+ max_def_level : 1 ,
2287+ max_rep_level : 0 ,
2288+ array,
2289+ logical_nulls,
2290+ } ;
2291+ // Chunk covering only the two null rows (levels 1..3), zero non-null values.
2292+ let sliced = levels. slice_for_chunk ( & CdcChunk {
2293+ level_offset : 1 ,
2294+ num_levels : 2 ,
2295+ value_offset : 1 ,
2296+ num_values : 0 ,
2297+ } ) ;
2298+ assert_eq ! ( sliced. def_levels, Some ( vec![ 0 , 0 ] ) ) ;
2299+ assert_eq ! ( sliced. non_null_indices, Vec :: <usize >:: new( ) ) ;
2300+ assert_eq ! ( sliced. array. len( ) , 0 ) ;
2301+ }
22732302}
0 commit comments