Skip to main content

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;
5
6use crate::ArrayRef;
7use crate::IntoArray;
8use crate::arrays::ListViewArray;
9use crate::arrays::ListViewVTable;
10use crate::compute::MaskReduce;
11use crate::validity::Validity;
12use crate::vtable::ValidityHelper;
13
14impl MaskReduce for ListViewVTable {
15    fn mask(array: &ListViewArray, mask: &ArrayRef) -> VortexResult<Option<ArrayRef>> {
16        // SAFETY: masking the validity does not affect the invariants
17        Ok(Some(
18            unsafe {
19                ListViewArray::new_unchecked(
20                    array.elements().clone(),
21                    array.offsets().clone(),
22                    array.sizes().clone(),
23                    array
24                        .validity()
25                        .clone()
26                        .and(Validity::Array(mask.clone()))?,
27                )
28                .with_zero_copy_to_list(array.is_zero_copy_to_list())
29            }
30            .into_array(),
31        ))
32    }
33}