vortex_array/arrays/listview/compute/
mask.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexResult;
5use vortex_mask::Mask;
6
7use crate::ArrayRef;
8use crate::IntoArray;
9use crate::arrays::ListViewArray;
10use crate::arrays::ListViewVTable;
11use crate::compute::MaskKernel;
12use crate::compute::MaskKernelAdapter;
13use crate::register_kernel;
14use crate::vtable::ValidityHelper;
15
16impl MaskKernel for ListViewVTable {
17    fn mask(&self, array: &ListViewArray, mask: &Mask) -> VortexResult<ArrayRef> {
18        // SAFETY: Since we are only masking the validity and everything else comes from an already
19        // valid `ListViewArray`, all of the invariants are still upheld.
20        Ok(unsafe {
21            ListViewArray::new_unchecked(
22                array.elements().clone(),
23                array.offsets().clone(),
24                array.sizes().clone(),
25                array.validity().mask(mask),
26            )
27            .with_zero_copy_to_list(array.is_zero_copy_to_list())
28        }
29        .into_array())
30    }
31}
32
33register_kernel!(MaskKernelAdapter(ListViewVTable).lift());