vortex_array/arrays/bool/compute/
boolean.rs1use vortex_error::VortexResult;
5use vortex_error::vortex_err;
6
7use crate::ArrayRef;
8use crate::ExecutionCtx;
9use crate::array::ArrayView;
10use crate::arrays::Bool;
11use crate::arrays::Constant;
12use crate::arrays::bool::BoolArrayExt;
13use crate::scalar_fn::fns::binary::BooleanKernel;
14use crate::scalar_fn::fns::binary::kleene_boolean_buffer_scalar;
15use crate::scalar_fn::fns::binary::kleene_boolean_buffers;
16use crate::scalar_fn::fns::operators::Operator;
17
18impl BooleanKernel for Bool {
19 fn boolean(
20 lhs: ArrayView<'_, Self>,
21 rhs: &ArrayRef,
22 operator: Operator,
23 ctx: &mut ExecutionCtx,
24 ) -> VortexResult<Option<ArrayRef>> {
25 let nullability = lhs.dtype().nullability() | rhs.dtype().nullability();
26
27 if let Some(rhs) = rhs.as_opt::<Constant>() {
28 let rhs = rhs
29 .scalar()
30 .as_bool_opt()
31 .ok_or_else(|| vortex_err!("expected boolean scalar"))?;
32 return kleene_boolean_buffer_scalar(
33 lhs.to_bit_buffer(),
34 lhs.validity()?,
35 &rhs,
36 operator,
37 nullability,
38 ctx,
39 )
40 .map(Some);
41 }
42
43 let Some(rhs) = rhs.as_opt::<Bool>() else {
44 return Ok(None);
45 };
46
47 kleene_boolean_buffers(
48 lhs.to_bit_buffer(),
49 lhs.validity()?,
50 rhs.to_bit_buffer(),
51 rhs.validity()?,
52 operator,
53 nullability,
54 ctx,
55 )
56 .map(Some)
57 }
58}