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::ExecutionCtx;
8use crate::arrays::BoolArray;
9use crate::arrays::bool::BoolArrayExt;
10
11impl BoolArray {
12    pub fn opt_bool_vec(&self, ctx: &mut ExecutionCtx) -> Vec<Option<bool>> {
13        self.validity()
14            .vortex_expect("failed to get validity")
15            .execute_mask(self.as_ref().len(), ctx)
16            .vortex_expect("Failed to compute validity mask")
17            .to_bit_buffer()
18            .iter()
19            .zip(self.to_bit_buffer().iter())
20            .map(|(valid, value)| valid.then_some(value))
21            .collect()
22    }
23
24    pub fn bool_vec(&self, ctx: &mut ExecutionCtx) -> Vec<bool> {
25        self.validity()
26            .vortex_expect("failed to get validity")
27            .execute_mask(self.as_ref().len(), ctx)
28            .vortex_expect("Failed to compute validity mask")
29            .to_bit_buffer()
30            .iter()
31            .zip(self.to_bit_buffer().iter())
32            .map(|(valid, value)| {
33                if !valid {
34                    vortex_panic!("trying to get bool values from an array with null elements")
35                }
36
37                value
38            })
39            .collect()
40    }
41}