Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where operations were negated instead of swapped when lhs/rhs were flipped #619

Merged
merged 1 commit into from
Aug 14, 2024
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
10 changes: 5 additions & 5 deletions vortex-array/src/array/primitive/compute/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ use crate::compute::CompareFn;
use crate::{Array, IntoArray, IntoArrayVariant};

impl CompareFn for PrimitiveArray {
fn compare(&self, other: &Array, predicate: Operator) -> VortexResult<Array> {
let flattened = other.clone().into_primitive()?;
fn compare(&self, other: &Array, operator: Operator) -> VortexResult<Array> {
let other = other.clone().into_primitive()?;

let matching_idxs = match_each_native_ptype!(self.ptype(), |$T| {
let predicate_fn = &predicate.to_predicate::<$T>();
apply_predicate(self.maybe_null_slice::<$T>(), flattened.maybe_null_slice::<$T>(), predicate_fn)
let predicate_fn = &operator.to_predicate::<$T>();
apply_predicate(self.maybe_null_slice::<$T>(), other.maybe_null_slice::<$T>(), predicate_fn)
});

let present = self
.validity()
.to_logical(self.len())
.to_null_buffer()?
.map(|b| b.into_inner());
let present_other = flattened
let present_other = other
.validity()
.to_logical(self.len())
.to_null_buffer()?
Expand Down
7 changes: 3 additions & 4 deletions vortex-array/src/compute/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ pub fn compare(left: &Array, right: &Array, operator: Operator) -> VortexResult<
return selection;
}

if let Some(selection) = right.with_dyn(|rhs| {
rhs.compare()
.map(|rhs| rhs.compare(left, operator.inverse()))
}) {
if let Some(selection) =
right.with_dyn(|rhs| rhs.compare().map(|rhs| rhs.compare(left, operator.swap())))
{
return selection;
}

Expand Down
12 changes: 12 additions & 0 deletions vortex-expr/src/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ impl Operator {
}
}

/// Change the sides of the operator, where changing lhs and rhs won't change the result of the operation
pub fn swap(self) -> Self {
match self {
Operator::Eq => Operator::Eq,
Operator::NotEq => Operator::NotEq,
Operator::Gt => Operator::Lte,
Operator::Gte => Operator::Lt,
Operator::Lt => Operator::Gte,
Operator::Lte => Operator::Gt,
}
}

pub fn to_predicate<T: NativePType>(&self) -> fn(&T, &T) -> bool {
match self {
Operator::Eq => PartialEq::eq,
Expand Down
Loading