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