diff --git a/vortex-array/src/scalar_fn/fns/between/mod.rs b/vortex-array/src/scalar_fn/fns/between/mod.rs index 2151a310dde..01c4fe06d31 100644 --- a/vortex-array/src/scalar_fn/fns/between/mod.rs +++ b/vortex-array/src/scalar_fn/fns/between/mod.rs @@ -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. diff --git a/vortex-array/src/scalar_fn/fns/binary/boolean.rs b/vortex-array/src/scalar_fn/fns/binary/boolean.rs index b7f838c6d13..3fb91016e3e 100644 --- a/vortex-array/src/scalar_fn/fns/binary/boolean.rs +++ b/vortex-array/src/scalar_fn/fns/binary/boolean.rs @@ -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; @@ -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; @@ -116,67 +113,32 @@ pub fn or_kleene(lhs: &ArrayRef, rhs: &ArrayRef) -> VortexResult { /// 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 { - 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::() - && let Some(result) = ::boolean(lhs, rhs, op, ctx)? - { - return Ok(result); - } - - if let Some(rhs) = rhs.as_opt::() - && let Some(result) = ::boolean(rhs, lhs, op, ctx)? - { + let lhs = lhs.execute::(ctx)?; + if let Some(result) = ::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 { - 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::(ctx)?; + let Some(result) = ::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. diff --git a/vortex-array/src/scalar_fn/fns/binary/mod.rs b/vortex-array/src/scalar_fn/fns/binary/mod.rs index 156540a2820..361c4fab240 100644 --- a/vortex-array/src/scalar_fn/fns/binary/mod.rs +++ b/vortex-array/src/scalar_fn/fns/binary/mod.rs @@ -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),