vortex_array/arrays/bool/
test.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use itertools::Itertools;
5use vortex_error::{VortexResult, vortex_bail};
6
7use crate::arrays::BoolArray;
8
9impl BoolArray {
10    pub fn opt_bool_vec(&self) -> VortexResult<Vec<Option<bool>>> {
11        Ok(self
12            .validity_mask()
13            .to_boolean_buffer()
14            .into_iter()
15            .zip(self.boolean_buffer().iter())
16            .map(move |(valid, value)| valid.then_some(value))
17            .collect_vec())
18    }
19
20    pub fn bool_vec(&self) -> VortexResult<Vec<bool>> {
21        self.validity_mask()
22            .to_boolean_buffer()
23            .into_iter()
24            .zip(self.boolean_buffer().iter())
25            .map(move |(valid, value)| {
26                if !valid {
27                    vortex_bail!("trying to get bool values from an array with null elements")
28                }
29
30                Ok(value)
31            })
32            .try_collect()
33    }
34}