Skip to main content

vortex_array/arrays/decimal/compute/
mask.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_dtype::match_each_decimal_value_type;
5use vortex_error::VortexResult;
6
7use crate::ArrayRef;
8use crate::IntoArray;
9use crate::arrays::DecimalArray;
10use crate::arrays::DecimalVTable;
11use crate::compute::MaskReduce;
12use crate::validity::Validity;
13use crate::vtable::ValidityHelper;
14
15impl MaskReduce for DecimalVTable {
16    fn mask(array: &DecimalArray, mask: &ArrayRef) -> VortexResult<Option<ArrayRef>> {
17        Ok(Some(match_each_decimal_value_type!(
18            array.values_type(),
19            |D| {
20                // SAFETY: masking the validity does not affect the invariants
21                unsafe {
22                    DecimalArray::new_unchecked(
23                        array.buffer::<D>(),
24                        array.decimal_dtype(),
25                        array
26                            .validity()
27                            .clone()
28                            .and(Validity::Array(mask.clone()))?,
29                    )
30                }
31                .into_array()
32            }
33        )))
34    }
35}