vortex_array/arrays/scalar_fn/vtable/
validity.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexExpect;
5use vortex_mask::Mask;
6
7use crate::Array;
8use crate::arrays::scalar_fn::array::ScalarFnArray;
9use crate::arrays::scalar_fn::vtable::SCALAR_FN_SESSION;
10use crate::arrays::scalar_fn::vtable::ScalarFnVTable;
11use crate::expr::functions::NullHandling;
12use crate::vtable::ValidityVTable;
13
14impl ValidityVTable<ScalarFnVTable> for ScalarFnVTable {
15    fn is_valid(array: &ScalarFnArray, index: usize) -> bool {
16        array.scalar_at(index).is_valid()
17    }
18
19    fn all_valid(array: &ScalarFnArray) -> bool {
20        match array.scalar_fn.signature().null_handling() {
21            NullHandling::Propagate | NullHandling::AbsorbsNull => {
22                // Requires all children to guarantee all_valid
23                array.children().iter().all(|child| child.all_valid())
24            }
25            NullHandling::Custom => {
26                // We cannot guarantee that the array is all valid without evaluating the function
27                false
28            }
29        }
30    }
31
32    fn all_invalid(array: &ScalarFnArray) -> bool {
33        match array.scalar_fn.signature().null_handling() {
34            NullHandling::Propagate => {
35                // All null if any child is all null
36                array.children().iter().any(|child| child.all_invalid())
37            }
38            NullHandling::AbsorbsNull | NullHandling::Custom => {
39                // We cannot guarantee that the array is all valid without evaluating the function
40                false
41            }
42        }
43    }
44
45    fn validity_mask(array: &ScalarFnArray) -> Mask {
46        let vector = array
47            .execute(&SCALAR_FN_SESSION)
48            .vortex_expect("Validity mask computation should be fallible");
49        Mask::from_buffer(vector.into_bool().into_bits())
50    }
51}