Skip to main content

vortex_array/arrays/bool/
test_harness.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use vortex_error::VortexExpect;
5use vortex_error::vortex_panic;
6
7use crate::LEGACY_SESSION;
8use crate::VortexSessionExecute;
9use crate::arrays::BoolArray;
10use crate::arrays::bool::BoolArrayExt;
11
12impl BoolArray {
13    pub fn opt_bool_vec(&self) -> Vec<Option<bool>> {
14        self.validity()
15            .vortex_expect("failed to get validity")
16            .to_mask(
17                self.as_ref().len(),
18                &mut LEGACY_SESSION.create_execution_ctx(),
19            )
20            .vortex_expect("Failed to compute validity mask")
21            .to_bit_buffer()
22            .iter()
23            .zip(self.to_bit_buffer().iter())
24            .map(|(valid, value)| valid.then_some(value))
25            .collect()
26    }
27
28    pub fn bool_vec(&self) -> Vec<bool> {
29        self.validity()
30            .vortex_expect("failed to get validity")
31            .to_mask(
32                self.as_ref().len(),
33                &mut LEGACY_SESSION.create_execution_ctx(),
34            )
35            .vortex_expect("Failed to compute validity mask")
36            .to_bit_buffer()
37            .iter()
38            .zip(self.to_bit_buffer().iter())
39            .map(|(valid, value)| {
40                if !valid {
41                    vortex_panic!("trying to get bool values from an array with null elements")
42                }
43
44                value
45            })
46            .collect()
47    }
48}