Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vortex-array/src/scalar_fn/fns/between/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ fn between_canonical(
upper.clone(),
Operator::from(options.upper_strict.to_compare_operator()),
)?;
execute_boolean(&lower_cmp, &upper_cmp, Operator::And, ctx)
execute_boolean(lower_cmp, upper_cmp, Operator::And, ctx)
}

/// An optimized scalar expression to compute whether values fall between two bounds.
Expand Down
60 changes: 11 additions & 49 deletions vortex-array/src/scalar_fn/fns/binary/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use std::iter::repeat_n;

use arrow_array::cast::AsArray;
use vortex_buffer::BitBuffer;
use vortex_buffer::BufferMut;
use vortex_buffer::read_u64_le;
Expand All @@ -27,8 +26,6 @@ use crate::arrays::ScalarFn;
use crate::arrays::scalar_fn::ExactScalarFn;
use crate::arrays::scalar_fn::ScalarFnArrayExt;
use crate::arrays::scalar_fn::ScalarFnArrayView;
use crate::arrow::ArrowSessionExt;
use crate::arrow::FromArrowArray;
use crate::builtins::ArrayBuiltins;
use crate::dtype::DType;
use crate::dtype::Nullability;
Expand Down Expand Up @@ -116,67 +113,32 @@ pub fn or_kleene(lhs: &ArrayRef, rhs: &ArrayRef) -> VortexResult<ArrayRef> {
/// This is the entry point for boolean operations from the binary expression.
/// Handles constants and canonical boolean arrays directly, otherwise falls back to Arrow.
pub(crate) fn execute_boolean(
lhs: &ArrayRef,
rhs: &ArrayRef,
lhs: ArrayRef,
rhs: ArrayRef,
op: Operator,
ctx: &mut ExecutionCtx,
) -> VortexResult<ArrayRef> {
let nullable = boolean_nullability(lhs, rhs);
let nullable = boolean_nullability(&lhs, &rhs);

if lhs.is_empty() {
return Ok(Canonical::empty(&DType::Bool(nullable)).into_array());
}

if let Some(result) = constant_boolean(lhs, rhs, op)? {
if let Some(result) = constant_boolean(&lhs, &rhs, op)? {
return Ok(result);
}

if let Some(lhs) = lhs.as_opt::<Bool>()
&& let Some(result) = <Bool as BooleanKernel>::boolean(lhs, rhs, op, ctx)?
{
return Ok(result);
}

if let Some(rhs) = rhs.as_opt::<Bool>()
&& let Some(result) = <Bool as BooleanKernel>::boolean(rhs, lhs, op, ctx)?
{
let lhs = lhs.execute::<BoolArray>(ctx)?;
if let Some(result) = <Bool as BooleanKernel>::boolean(lhs.as_view(), &rhs, op, ctx)? {
return Ok(result);
}

arrow_execute_boolean(lhs.clone(), rhs.clone(), op, ctx)
}

/// Arrow implementation for Kleene boolean operations using [`Operator`].
fn arrow_execute_boolean(
lhs: ArrayRef,
rhs: ArrayRef,
op: Operator,
ctx: &mut ExecutionCtx,
) -> VortexResult<ArrayRef> {
let nullable = boolean_nullability(&lhs, &rhs);
let session = ctx.session().clone();

let lhs = session
.arrow()
.execute_arrow(lhs, None, ctx)?
.as_boolean_opt()
.ok_or_else(|| vortex_err!("expected lhs to be boolean"))?
.clone();

let rhs = session
.arrow()
.execute_arrow(rhs, None, ctx)?
.as_boolean_opt()
.ok_or_else(|| vortex_err!("expected rhs to be boolean"))?
.clone();

let array = match op {
Operator::And => arrow_arith::boolean::and_kleene(&lhs, &rhs)?,
Operator::Or => arrow_arith::boolean::or_kleene(&lhs, &rhs)?,
other => vortex_bail!("Not a boolean operator: {other}"),
let rhs = rhs.execute::<BoolArray>(ctx)?;
let Some(result) = <Bool as BooleanKernel>::boolean(rhs.as_view(), &lhs.into_array(), op, ctx)?
else {
vortex_bail!("No boolean kernel for two BoolArrays");
};

ArrayRef::from_arrow(&array, nullable == Nullability::Nullable)
Ok(result)
}

/// Handles boolean operations where at least one operand is a constant array.
Expand Down
4 changes: 2 additions & 2 deletions vortex-array/src/scalar_fn/fns/binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ impl ScalarFnVTable for Binary {
Operator::Lte => execute_compare(&lhs, &rhs, CompareOperator::Lte, ctx),
Operator::Gt => execute_compare(&lhs, &rhs, CompareOperator::Gt, ctx),
Operator::Gte => execute_compare(&lhs, &rhs, CompareOperator::Gte, ctx),
Operator::And => execute_boolean(&lhs, &rhs, Operator::And, ctx),
Operator::Or => execute_boolean(&lhs, &rhs, Operator::Or, ctx),
Operator::And => execute_boolean(lhs, rhs, Operator::And, ctx),
Operator::Or => execute_boolean(lhs, rhs, Operator::Or, ctx),
Operator::Add => execute_numeric(&lhs, &rhs, NumericOperator::Add, ctx),
Operator::Sub => execute_numeric(&lhs, &rhs, NumericOperator::Sub, ctx),
Operator::Mul => execute_numeric(&lhs, &rhs, NumericOperator::Mul, ctx),
Expand Down
Loading