Skip to content

Commit

Permalink
Fix infinite loop in constant array compare (#1016)
Browse files Browse the repository at this point in the history
  • Loading branch information
robert3005 authored Oct 11, 2024
1 parent bb8a373 commit 969692c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions vortex-array/src/compute/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub fn compare(
vortex_bail!("Compare operations only support arrays of the same type");
}

if left.is_encoding(Constant::ID) {
if left.is_encoding(Constant::ID) && !right.is_encoding(Constant::ID) {
return compare(right, left, operator.swap());
}

Expand Down Expand Up @@ -143,9 +143,10 @@ pub fn scalar_cmp(lhs: &Scalar, rhs: &Scalar, operator: Operator) -> Scalar {
#[cfg(test)]
mod tests {
use itertools::Itertools;
use vortex_scalar::ScalarValue;

use super::*;
use crate::array::BoolArray;
use crate::array::{BoolArray, ConstantArray};
use crate::validity::Validity;
use crate::{IntoArray, IntoArrayVariant};

Expand Down Expand Up @@ -220,4 +221,14 @@ mod tests {
.unwrap();
assert_eq!(to_int_indices(matches), [4u64]);
}

#[test]
fn constant_compare() {
let left = ConstantArray::new(Scalar::from(2u32), 10);
let right = ConstantArray::new(Scalar::from(10u32), 10);

let res = ConstantArray::try_from(compare(left, right, Operator::Gt).unwrap()).unwrap();
assert_eq!(res.scalar_value(), &ScalarValue::Bool(false));
assert_eq!(res.len(), 10);
}
}

0 comments on commit 969692c

Please sign in to comment.