vortex_arrow/executor/
bool.rs1use std::sync::Arc;
5
6use arrow_array::ArrayRef as ArrowArrayRef;
7use arrow_array::BooleanArray as ArrowBooleanArray;
8use vortex_array::ArrayRef;
9use vortex_array::ExecutionCtx;
10use vortex_array::arrays::BoolArray;
11use vortex_array::arrays::bool::BoolArrayExt;
12use vortex_array::dtype::DType;
13use vortex_error::VortexResult;
14use vortex_error::vortex_ensure;
15
16use crate::null_buffer::to_null_buffer;
17
18pub fn canonical_bool_to_arrow(
20 array: &BoolArray,
21 ctx: &mut ExecutionCtx,
22) -> VortexResult<ArrowArrayRef> {
23 Ok(Arc::new(ArrowBooleanArray::new(
24 array.to_bit_buffer().into(),
25 to_null_buffer(
26 array
27 .as_ref()
28 .validity()?
29 .execute_mask(array.as_ref().len(), ctx)?,
30 ),
31 )))
32}
33
34pub(super) fn to_arrow_bool(
35 array: ArrayRef,
36 ctx: &mut ExecutionCtx,
37) -> VortexResult<ArrowArrayRef> {
38 vortex_ensure!(
39 matches!(array.dtype(), DType::Bool(_)),
40 "Cannot convert Vortex array with dtype {} to an Arrow Boolean array",
41 array.dtype()
42 );
43 let bool_array = array.execute::<BoolArray>(ctx)?;
44 canonical_bool_to_arrow(&bool_array, ctx)
45}