Skip to main content

vortex_array/arrays/list/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::array::ArrayView;
9use crate::arrays::List;
10use crate::arrays::ListArray;
11use crate::arrays::list::ListArraySlotsExt;
12use crate::scalar_fn::fns::mask::MaskReduce;
13use crate::validity::Validity;
14
15impl MaskReduce for List {
16    const VALIDITY_IS_METADATA_ONLY: bool = true;
17
18    fn mask(array: ArrayView<'_, List>, mask: &ArrayRef) -> VortexResult<Option<ArrayRef>> {
19        // SAFETY: elements and offsets are unchanged, and masking only removes valid rows.
20        Ok(Some(unsafe {
21            ListArray::new_unchecked(
22                array.elements().clone(),
23                array.offsets().clone(),
24                array.validity()?.and(Validity::Array(mask.clone()))?,
25            )
26            .into_array()
27        }))
28    }
29}