@@ -181,9 +181,12 @@ impl ListReader {
181181
182182 Ok ( async move {
183183 let ( offsets, elements, validity) = try_join ! ( offsets_fut, elements_fut, validity_fut) ?;
184- let list =
185- ListArray :: try_new ( elements, offsets, create_validity ( validity, nullability) ) ?
186- . into_array ( ) ;
184+ // SAFETY: ListLayout is constructed from a valid ListArray and reading its children
185+ // without transformation preserves the list invariants.
186+ let list = unsafe {
187+ ListArray :: new_unchecked ( elements, offsets, create_validity ( validity, nullability) )
188+ }
189+ . into_array ( ) ;
187190
188191 // Filter before applying the expression: the expression may depend on the filtered
189192 // rows being removed (e.g. `cast(a, u8) where a < 256`).
@@ -229,9 +232,13 @@ impl ListReader {
229232
230233 // Rebase the offsets to index into the sliced elements buffer.
231234 let offsets = rebase_offsets ( offsets, elements_range. start ) ?;
232- let list =
233- ListArray :: try_new ( elements, offsets, create_validity ( validity, nullability) ) ?
234- . into_array ( ) ;
235+ // SAFETY: the ListLayout children were written from a valid ListArray. Slicing the
236+ // elements to the first and last offsets and rebasing every offset by the first one
237+ // preserves the list invariants.
238+ let list = unsafe {
239+ ListArray :: new_unchecked ( elements, offsets, create_validity ( validity, nullability) )
240+ }
241+ . into_array ( ) ;
235242
236243 // Filter before applying the expression (see `project_all_concurrent`).
237244 let mask = mask. await ?;
@@ -349,7 +356,7 @@ impl LayoutReader for ListReader {
349356 Ok ( ( ) )
350357 }
351358
352- //TODO(mk): handle zones for lists
359+ // TODO(mk): handle zones for lists
353360 fn pruning_evaluation (
354361 & self ,
355362 _row_range : & Range < u64 > ,
0 commit comments