Skip to main content

vortex_array/arrays/patched/
array.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::fmt::Display;
5use std::fmt::Formatter;
6use std::ops::Range;
7
8use vortex_buffer::Buffer;
9use vortex_buffer::BufferMut;
10use vortex_error::VortexResult;
11use vortex_error::vortex_ensure;
12use vortex_error::vortex_ensure_eq;
13use vortex_error::vortex_err;
14
15use crate::ArrayRef;
16use crate::ArraySlots;
17use crate::Canonical;
18use crate::ExecutionCtx;
19use crate::IntoArray;
20use crate::array::Array;
21use crate::array::ArrayParts;
22use crate::array::TypedArrayRef;
23use crate::array_slots;
24use crate::arrays::Patched;
25use crate::arrays::PrimitiveArray;
26use crate::arrays::patched::TransposedPatches;
27use crate::arrays::patched::patch_lanes;
28use crate::buffer::BufferHandle;
29use crate::dtype::DType;
30use crate::dtype::IntegerPType;
31use crate::dtype::NativePType;
32use crate::dtype::PType;
33use crate::match_each_native_ptype;
34use crate::match_each_unsigned_integer_ptype;
35use crate::patches::Patches;
36use crate::validity::Validity;
37
38#[derive(Debug, Clone)]
39pub struct PatchedData {
40    /// Number of lanes the patch indices and values have been split into. Each of the `n_chunks`
41    /// of 1024 values is split into `n_lanes` lanes horizontally, each lane having 1024 / n_lanes
42    /// values that might be patched.
43    pub(super) n_lanes: usize,
44
45    /// The offset into that first chunk that is considered in bounds.
46    ///
47    /// The patch indices of the first chunk less than `offset` should be skipped, and the offset
48    /// should be subtracted out of the remaining offsets to get their final position in the
49    /// executed array.
50    pub(super) offset: usize,
51}
52
53#[array_slots(Patched)]
54pub struct PatchedSlots {
55    /// The inner array containing the base unpatched values.
56    #[slot(0)]
57    pub inner: ArrayRef,
58    /// The lane offsets array for locating patches within lanes.
59    #[slot(1)]
60    pub lane_offsets: ArrayRef,
61    /// The indices of patched (exception) values.
62    #[slot(2)]
63    pub patch_indices: ArrayRef,
64    /// The patched (exception) values at the corresponding indices.
65    #[slot(3)]
66    pub patch_values: ArrayRef,
67}
68
69impl Display for PatchedData {
70    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
71        write!(f, "n_lanes: {}, offset: {}", self.n_lanes, self.offset)
72    }
73}
74
75impl PatchedData {
76    /// Checks the lane count, offset and dtype, and returns the length of the `lane_offsets`
77    /// child: one entry per lane of each chunk holding `offset + len` values, plus a final end
78    /// offset.
79    pub(crate) fn lane_offsets_len(&self, dtype: &DType, len: usize) -> VortexResult<usize> {
80        vortex_ensure!(
81            dtype.is_primitive(),
82            "PatchedArray dtype must be primitive, got {dtype}"
83        );
84        vortex_ensure!(
85            self.n_lanes.is_power_of_two() && self.n_lanes <= 128,
86            "PatchedArray n_lanes must be a power of two between 1 and 128, got {}",
87            self.n_lanes
88        );
89        vortex_ensure!(
90            self.offset < 1024,
91            "PatchedArray offset must be less than 1024, got {}",
92            self.offset
93        );
94        self.offset
95            .checked_add(len)
96            .map(|end| end.div_ceil(1024))
97            .and_then(|n_chunks| n_chunks.checked_mul(self.n_lanes))
98            .and_then(|n_offsets| n_offsets.checked_add(1))
99            .ok_or_else(|| vortex_err!("PatchedArray lane offsets length overflowed usize"))
100    }
101
102    pub(crate) fn validate(
103        &self,
104        dtype: &DType,
105        len: usize,
106        slots: &PatchedSlotsView,
107    ) -> VortexResult<()> {
108        let lane_offsets_len = self.lane_offsets_len(dtype, len)?;
109        vortex_ensure_eq!(
110            slots.lane_offsets.dtype(),
111            <&DType>::from(PType::U32),
112            "PatchedArray lane offsets must be non-nullable u32",
113        );
114        vortex_ensure_eq!(slots.lane_offsets.len(), lane_offsets_len);
115        vortex_ensure_eq!(
116            slots.patch_indices.dtype(),
117            <&DType>::from(PType::U16),
118            "PatchedArray patch indices must be non-nullable u16",
119        );
120        vortex_ensure_eq!(
121            slots.patch_values.dtype(),
122            &dtype.as_nonnullable(),
123            "PatchedArray patch values must have the non-nullable outer dtype",
124        );
125        vortex_ensure_eq!(
126            slots.inner.dtype(),
127            dtype,
128            "PatchedArray base dtype does not match outer dtype",
129        );
130        vortex_ensure_eq!(
131            slots.inner.len(),
132            len,
133            "PatchedArray base len does not match outer len",
134        );
135        vortex_ensure_eq!(
136            slots.patch_indices.len(),
137            slots.patch_values.len(),
138            "PatchedArray patch indices len does not match patch values len",
139        );
140        Ok(())
141    }
142}
143
144pub trait PatchedArrayExt: TypedArrayRef<Patched> {
145    #[inline]
146    fn n_lanes(&self) -> usize {
147        self.n_lanes
148    }
149
150    #[inline]
151    fn offset(&self) -> usize {
152        self.offset
153    }
154
155    #[inline]
156    fn lane_range(
157        &self,
158        chunk: usize,
159        lane: usize,
160        ctx: &mut ExecutionCtx,
161    ) -> VortexResult<Range<usize>> {
162        assert!(chunk * 1024 <= self.len() + self.offset());
163        assert!(lane < self.n_lanes());
164
165        let start = self
166            .lane_offsets()
167            .execute_scalar(chunk * self.n_lanes() + lane, ctx)?;
168        let stop = self
169            .lane_offsets()
170            .execute_scalar(chunk * self.n_lanes() + lane + 1, ctx)?;
171
172        let start = start
173            .as_primitive()
174            .as_::<usize>()
175            .ok_or_else(|| vortex_err!("could not cast lane_offset to usize"))?;
176
177        let stop = stop
178            .as_primitive()
179            .as_::<usize>()
180            .ok_or_else(|| vortex_err!("could not cast lane_offset to usize"))?;
181
182        Ok(start..stop)
183    }
184
185    fn slice_chunks(&self, chunks: Range<usize>) -> VortexResult<Array<Patched>> {
186        let lane_offsets_start = chunks.start * self.n_lanes();
187        let lane_offsets_stop = chunks.end * self.n_lanes() + 1;
188
189        let sliced_lane_offsets = self
190            .lane_offsets()
191            .slice(lane_offsets_start..lane_offsets_stop)?;
192        let indices = self.patch_indices().clone();
193        let values = self.patch_values().clone();
194
195        let begin = (chunks.start * 1024).saturating_sub(self.offset());
196        let end = (chunks.end * 1024)
197            .saturating_sub(self.offset())
198            .min(self.len());
199
200        let offset = if chunks.start == 0 { self.offset() } else { 0 };
201        let inner = self.inner().slice(begin..end)?;
202        let len = inner.len();
203        let dtype = self.dtype().clone();
204        let slots = PatchedSlots {
205            inner,
206            lane_offsets: sliced_lane_offsets,
207            patch_indices: indices,
208            patch_values: values,
209        }
210        .into_slots();
211
212        Ok(unsafe { Patched::new_unchecked(dtype, len, slots, self.n_lanes(), offset) })
213    }
214}
215
216impl<T: TypedArrayRef<Patched>> PatchedArrayExt for T {}
217
218impl Patched {
219    pub fn from_array_and_patches(
220        inner: ArrayRef,
221        patches: &Patches,
222        ctx: &mut ExecutionCtx,
223    ) -> VortexResult<Array<Patched>> {
224        vortex_ensure!(
225            inner.dtype().eq_with_nullability_superset(patches.dtype()),
226            "array DType must match patches DType"
227        );
228
229        vortex_ensure!(
230            inner.dtype().is_primitive(),
231            "Creating PatchedArray from Patches only supported for primitive arrays"
232        );
233
234        vortex_ensure!(
235            patches.num_patches() <= u32::MAX as usize,
236            "PatchedArray does not support > u32::MAX patch values"
237        );
238
239        vortex_ensure!(
240            patches.values().all_valid(ctx)?,
241            "PatchedArray cannot be built from Patches with nulls"
242        );
243
244        let values_ptype = patches.dtype().as_ptype();
245
246        let TransposedPatches {
247            n_lanes,
248            lane_offsets,
249            indices,
250            values,
251        } = transpose_patches(patches, ctx)?;
252
253        let lane_offsets = PrimitiveArray::from_buffer_handle(
254            BufferHandle::new_host(lane_offsets),
255            PType::U32,
256            Validity::NonNullable,
257        )
258        .into_array();
259        let indices = PrimitiveArray::from_buffer_handle(
260            BufferHandle::new_host(indices),
261            PType::U16,
262            Validity::NonNullable,
263        )
264        .into_array();
265        let values = PrimitiveArray::from_buffer_handle(
266            BufferHandle::new_host(values),
267            values_ptype,
268            Validity::NonNullable,
269        )
270        .into_array();
271
272        let dtype = inner.dtype().clone();
273        let len = inner.len();
274        let slots = PatchedSlots {
275            inner,
276            lane_offsets,
277            patch_indices: indices,
278            patch_values: values,
279        }
280        .into_slots();
281        Ok(unsafe { Self::new_unchecked(dtype, len, slots, n_lanes, 0) })
282    }
283
284    pub(crate) unsafe fn new_unchecked(
285        dtype: DType,
286        len: usize,
287        slots: ArraySlots,
288        n_lanes: usize,
289        offset: usize,
290    ) -> Array<Patched> {
291        unsafe {
292            Array::from_parts_unchecked(ArrayParts::new(
293                Patched,
294                dtype,
295                len,
296                PatchedData { n_lanes, offset },
297                slots,
298            ))
299        }
300    }
301}
302
303/// Transpose a set of patches from the default sorted layout into the data parallel layout.
304fn transpose_patches(patches: &Patches, ctx: &mut ExecutionCtx) -> VortexResult<TransposedPatches> {
305    let array_len = patches.array_len();
306    let offset = patches.offset();
307
308    let indices = patches
309        .indices()
310        .clone()
311        .execute::<Canonical>(ctx)?
312        .into_primitive();
313
314    let values = patches
315        .values()
316        .clone()
317        .execute::<Canonical>(ctx)?
318        .into_primitive();
319
320    let indices_ptype = indices.ptype();
321    let values_ptype = values.ptype();
322
323    let indices = indices.buffer_handle().clone().unwrap_host();
324    let values = values.buffer_handle().clone().unwrap_host();
325
326    match_each_unsigned_integer_ptype!(indices_ptype, |I| {
327        match_each_native_ptype!(values_ptype, |V| {
328            let indices: Buffer<I> = Buffer::from_byte_buffer(indices);
329            let values: Buffer<V> = Buffer::from_byte_buffer(values);
330
331            Ok(transpose(
332                indices.as_slice(),
333                values.as_slice(),
334                offset,
335                array_len,
336            ))
337        })
338    })
339}
340
341#[expect(clippy::cast_possible_truncation)]
342fn transpose<I: IntegerPType, V: NativePType>(
343    indices_in: &[I],
344    values_in: &[V],
345    offset: usize,
346    array_len: usize,
347) -> TransposedPatches {
348    // Total number of slots is number of chunks times number of lanes.
349    let n_chunks = array_len.div_ceil(1024);
350    assert!(
351        n_chunks <= u32::MAX as usize,
352        "Cannot transpose patches for array with >= 4 trillion elements"
353    );
354
355    let n_lanes = patch_lanes::<V>();
356
357    // We know upfront how many indices and values we'll have.
358    let mut indices_buffer = BufferMut::with_capacity(indices_in.len());
359    let mut values_buffer = BufferMut::with_capacity(values_in.len());
360
361    // Number of patches in each chunk/lane.
362    let mut lane_offsets: BufferMut<u32> = BufferMut::zeroed(n_chunks * n_lanes + 1);
363
364    // Scan the index/value pairs once to get chunk/lane counts.
365    for index in indices_in {
366        let index = index.as_() - offset;
367        let chunk = index / 1024;
368        let lane = index % n_lanes;
369
370        lane_offsets[chunk * n_lanes + lane + 1] += 1;
371    }
372
373    for index in 1..lane_offsets.len() {
374        lane_offsets[index] += lane_offsets[index - 1];
375    }
376
377    // Loop over patches, writing them to final positions.
378    let indices_out = indices_buffer.spare_capacity_mut();
379    let values_out = values_buffer.spare_capacity_mut();
380    for (index, &value) in std::iter::zip(indices_in, values_in) {
381        let index = index.as_() - offset;
382        let chunk = index / 1024;
383        let lane = index % n_lanes;
384
385        let position = &mut lane_offsets[chunk * n_lanes + lane];
386        indices_out[*position as usize].write((index % 1024) as u16);
387        values_out[*position as usize].write(value);
388        *position += 1;
389    }
390
391    unsafe {
392        indices_buffer.set_len(indices_in.len());
393        values_buffer.set_len(values_in.len());
394    }
395
396    for index in indices_in {
397        let index = index.as_() - offset;
398        let chunk = index / 1024;
399        let lane = index % n_lanes;
400
401        lane_offsets[chunk * n_lanes + lane] -= 1;
402    }
403
404    TransposedPatches {
405        n_lanes,
406        lane_offsets: lane_offsets.freeze().into_byte_buffer(),
407        indices: indices_buffer.freeze().into_byte_buffer(),
408        values: values_buffer.freeze().into_byte_buffer(),
409    }
410}
411
412#[cfg(test)]
413mod tests {
414    use vortex_buffer::Buffer;
415    use vortex_buffer::buffer;
416
417    use super::PatchedSlots;
418    use crate::ArrayRef;
419    use crate::IntoArray;
420    use crate::array_slots;
421    use crate::arrays::Chunked;
422    use crate::arrays::Null;
423    use crate::arrays::PrimitiveArray;
424    use crate::arrays::Union;
425    use crate::validity::Validity;
426
427    #[array_slots(Null)]
428    struct OptionalPatchedSlots {
429        #[slot(0)]
430        required: ArrayRef,
431        #[slot(1)]
432        maybe: Option<ArrayRef>,
433    }
434
435    #[array_slots(Chunked)]
436    struct VariadicSlots {
437        #[slot(0)]
438        offsets: ArrayRef,
439        #[slot(1)]
440        maybe_validity: Option<ArrayRef>,
441        #[slot(2..)]
442        chunks: Vec<ArrayRef>,
443    }
444
445    /// The same layout as [`VariadicSlots`], but with every field declaration moved. The
446    /// `#[slot(..)]` annotations must keep the storage layout identical.
447    #[array_slots(Union)]
448    struct ShuffledVariadicSlots {
449        #[slot(2..)]
450        chunks: Vec<ArrayRef>,
451        #[slot(1)]
452        maybe_validity: Option<ArrayRef>,
453        #[slot(0)]
454        offsets: ArrayRef,
455    }
456
457    #[test]
458    fn generated_slots_round_trip() {
459        let required = PrimitiveArray::new(buffer![1u8, 2, 3], Validity::NonNullable).into_array();
460        let optional = PrimitiveArray::new(buffer![4u8, 5, 6], Validity::NonNullable).into_array();
461
462        let slot_vec = vec![Some(required.clone()), Some(optional.clone())];
463        let view = OptionalPatchedSlotsView::from_slots(&slot_vec);
464        assert!(ArrayRef::ptr_eq(view.required, &required));
465        assert!(ArrayRef::ptr_eq(
466            view.maybe.expect("optional slot"),
467            &optional
468        ));
469        assert_eq!(view.required.len(), 3);
470        assert_eq!(view.maybe.expect("optional slot").len(), 3);
471
472        let cloned = OptionalPatchedSlots::from_slots(slot_vec.into());
473        assert!(ArrayRef::ptr_eq(&cloned.required, &required));
474        assert!(ArrayRef::ptr_eq(
475            cloned.maybe.as_ref().expect("optional clone"),
476            &optional
477        ));
478        assert_eq!(cloned.required.len(), required.len());
479        assert_eq!(cloned.maybe.expect("optional clone").len(), optional.len());
480
481        let rebuilt = PatchedSlots::from_slots(
482            vec![
483                Some(required.clone()),
484                Some(optional.clone()),
485                Some(required.clone()),
486                Some(optional.clone()),
487            ]
488            .into(),
489        );
490        assert!(ArrayRef::ptr_eq(&rebuilt.inner, &required));
491        assert!(ArrayRef::ptr_eq(&rebuilt.lane_offsets, &optional));
492        assert!(ArrayRef::ptr_eq(&rebuilt.patch_indices, &required));
493        assert!(ArrayRef::ptr_eq(&rebuilt.patch_values, &optional));
494        assert_eq!(rebuilt.inner.len(), required.len());
495        assert_eq!(rebuilt.patch_values.len(), optional.len());
496    }
497
498    #[test]
499    #[allow(clippy::cognitive_complexity)]
500    fn variadic_slots_round_trip() {
501        let offsets = PrimitiveArray::new(buffer![0u64, 3, 5], Validity::NonNullable).into_array();
502        let chunk0 = PrimitiveArray::new(buffer![1u8, 2, 3], Validity::NonNullable).into_array();
503        let chunk1 = PrimitiveArray::new(buffer![4u8, 5], Validity::NonNullable).into_array();
504
505        assert_eq!(VariadicSlots::OFFSETS, 0);
506        assert_eq!(VariadicSlots::MAYBE_VALIDITY, 1);
507        assert_eq!(VariadicSlots::CHUNKS_OFFSET, 2);
508        assert_eq!(VariadicSlots::FIXED_COUNT, 2);
509        assert_eq!(VariadicSlots::slot_name(0), "offsets");
510        assert_eq!(VariadicSlots::slot_name(3), "chunks[1]");
511
512        let slot_vec = vec![
513            Some(offsets.clone()),
514            None,
515            Some(chunk0.clone()),
516            Some(chunk1.clone()),
517        ];
518
519        let view = VariadicSlotsView::from_slots(&slot_vec);
520        assert!(ArrayRef::ptr_eq(view.offsets, &offsets));
521        assert!(ArrayRef::ptr_eq(&view.chunks[0], &chunk0));
522        assert!(ArrayRef::ptr_eq(
523            view.chunks.get(1).expect("second chunk"),
524            &chunk1
525        ));
526        assert_eq!(view.offsets.len(), 3);
527        assert!(view.maybe_validity.is_none());
528        assert_eq!(view.chunks.len(), 2);
529        assert_eq!(view.chunks[0].len(), 3);
530        assert_eq!(view.chunks.get(1).map(|c| c.len()), Some(2));
531        assert!(view.chunks.get(2).is_none());
532        assert_eq!(
533            view.chunks.iter().map(|c| c.len()).collect::<Vec<_>>(),
534            vec![3, 2]
535        );
536
537        let owned = view.to_owned();
538        assert_eq!(owned.chunks.len(), 2);
539        assert!(ArrayRef::ptr_eq(&owned.offsets, &offsets));
540        assert!(owned.maybe_validity.is_none());
541        assert!(ArrayRef::ptr_eq(&owned.chunks[0], &chunk0));
542        assert!(ArrayRef::ptr_eq(&owned.chunks[1], &chunk1));
543
544        let owned = VariadicSlots::from_slots(slot_vec.into());
545        assert_eq!(owned.offsets.len(), offsets.len());
546        assert!(owned.maybe_validity.is_none());
547        assert_eq!(owned.chunks.len(), 2);
548
549        assert!(ArrayRef::ptr_eq(&owned.offsets, &offsets));
550        assert!(ArrayRef::ptr_eq(&owned.chunks[0], &chunk0));
551        assert!(ArrayRef::ptr_eq(&owned.chunks[1], &chunk1));
552        let slots = owned.into_slots();
553        assert_eq!(slots.len(), 4);
554        for (index, expected) in [(0, &offsets), (2, &chunk0), (3, &chunk1)] {
555            assert!(ArrayRef::ptr_eq(
556                slots[index].as_ref().expect("present slot"),
557                expected
558            ));
559        }
560        assert!(slots[1].is_none());
561        assert_eq!(
562            slots[VariadicSlots::CHUNKS_OFFSET]
563                .as_ref()
564                .map(|c| c.len()),
565            Some(3)
566        );
567    }
568
569    #[test]
570    fn variadic_slots_empty_tail() {
571        let offsets = PrimitiveArray::new(buffer![0u64], Validity::NonNullable).into_array();
572        let slot_vec = vec![Some(offsets), None];
573
574        let view = VariadicSlotsView::from_slots(&slot_vec);
575        assert!(view.chunks.is_empty());
576
577        let owned = VariadicSlots::from_slots(slot_vec.into());
578        assert!(owned.chunks.is_empty());
579        assert_eq!(owned.into_slots().len(), 2);
580    }
581
582    #[test]
583    fn variadic_slots_spilled_tail_keeps_order() {
584        let offsets = PrimitiveArray::new(buffer![0u64], Validity::NonNullable).into_array();
585        let chunks: Vec<ArrayRef> = (0..5u8)
586            .map(|len| {
587                PrimitiveArray::new((0..len).collect::<Buffer<u8>>(), Validity::NonNullable)
588                    .into_array()
589            })
590            .collect();
591
592        let slots = VariadicSlots {
593            offsets: offsets.clone(),
594            maybe_validity: None,
595            chunks,
596        }
597        .into_slots();
598
599        assert!(slots.spilled());
600        assert_eq!(slots.len(), VariadicSlots::FIXED_COUNT + 5);
601        assert_eq!(
602            slots[VariadicSlots::OFFSETS].as_ref().map(|s| s.len()),
603            Some(offsets.len())
604        );
605        assert!(slots[VariadicSlots::MAYBE_VALIDITY].is_none());
606        assert_eq!(
607            slots[VariadicSlots::CHUNKS_OFFSET..]
608                .iter()
609                .map(|s| s.as_ref().map(|c| c.len()))
610                .collect::<Vec<_>>(),
611            (0..5).map(Some).collect::<Vec<_>>()
612        );
613    }
614
615    #[test]
616    fn slot_indices_follow_annotations_not_declaration_order() {
617        assert_eq!(
618            ShuffledVariadicSlots::OFFSETS,
619            VariadicSlots::OFFSETS,
620            "field declaration order must not move a slot"
621        );
622        assert_eq!(
623            ShuffledVariadicSlots::MAYBE_VALIDITY,
624            VariadicSlots::MAYBE_VALIDITY
625        );
626        assert_eq!(
627            ShuffledVariadicSlots::CHUNKS_OFFSET,
628            VariadicSlots::CHUNKS_OFFSET
629        );
630        assert_eq!(
631            ShuffledVariadicSlots::FIXED_COUNT,
632            VariadicSlots::FIXED_COUNT
633        );
634        assert_eq!(ShuffledVariadicSlots::slot_name(0), "offsets");
635        assert_eq!(ShuffledVariadicSlots::slot_name(1), "maybe_validity");
636        assert_eq!(ShuffledVariadicSlots::slot_name(3), "chunks[1]");
637    }
638
639    #[test]
640    fn shuffled_declaration_order_round_trips_through_storage() {
641        let offsets = PrimitiveArray::new(buffer![0u64, 3], Validity::NonNullable).into_array();
642        let validity = PrimitiveArray::new(buffer![1u8, 1], Validity::NonNullable).into_array();
643        let chunk = PrimitiveArray::new(buffer![1u8, 2, 3], Validity::NonNullable).into_array();
644
645        let slot_vec = vec![
646            Some(offsets.clone()),
647            Some(validity.clone()),
648            Some(chunk.clone()),
649        ];
650
651        let view = ShuffledVariadicSlotsView::from_slots(&slot_vec);
652        assert!(ArrayRef::ptr_eq(view.offsets, &offsets));
653        assert!(ArrayRef::ptr_eq(
654            view.maybe_validity.expect("validity"),
655            &validity
656        ));
657        assert!(ArrayRef::ptr_eq(&view.chunks[0], &chunk));
658        assert_eq!(view.offsets.len(), offsets.len());
659        assert_eq!(view.maybe_validity.map(|v| v.len()), Some(validity.len()));
660        assert_eq!(view.chunks.len(), 1);
661        assert_eq!(view.chunks[0].len(), chunk.len());
662
663        // `into_slots` must emit annotation order, not the shuffled declaration order.
664        let round_tripped = ShuffledVariadicSlots::from_slots(slot_vec.into()).into_slots();
665        assert_eq!(round_tripped.len(), 3);
666        for (index, expected) in [&offsets, &validity, &chunk].into_iter().enumerate() {
667            assert!(ArrayRef::ptr_eq(
668                round_tripped[index].as_ref().expect("present slot"),
669                expected
670            ));
671        }
672        assert_eq!(
673            round_tripped[ShuffledVariadicSlots::OFFSETS]
674                .as_ref()
675                .map(|s| s.len()),
676            Some(offsets.len())
677        );
678        assert_eq!(
679            round_tripped[ShuffledVariadicSlots::MAYBE_VALIDITY]
680                .as_ref()
681                .map(|s| s.len()),
682            Some(validity.len())
683        );
684        assert_eq!(
685            round_tripped[ShuffledVariadicSlots::CHUNKS_OFFSET]
686                .as_ref()
687                .map(|s| s.len()),
688            Some(chunk.len())
689        );
690    }
691}