Skip to content
Closed
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
6 changes: 2 additions & 4 deletions vortex-array/src/array/primitive/compute/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ fn apply_predicate<T: NativePType, F: Fn(T, T) -> bool>(
let mut packed_block = 0_u64;
for bit_idx in 0..BLOCK_SIZE {
let idx = bit_idx + block * BLOCK_SIZE;
let r = f(unsafe { *lhs.get_unchecked(idx) }, unsafe {
*rhs.get_unchecked(idx)
});
let r = unsafe { f(*lhs.get_unchecked(idx), *rhs.get_unchecked(idx)) };
packed_block |= (r as u64) << bit_idx;
}

Expand All @@ -97,7 +95,7 @@ fn apply_predicate<T: NativePType, F: Fn(T, T) -> bool>(
let mut packed_block = 0_u64;
for bit_idx in 0..reminder {
let idx = bit_idx + block_count * BLOCK_SIZE;
let r = f(lhs[idx], rhs[idx]);
let r = unsafe { f(*lhs.get_unchecked(idx), *rhs.get_unchecked(idx)) };
packed_block |= (r as u64) << bit_idx;
}

Expand Down
32 changes: 28 additions & 4 deletions vortex-array/src/compute/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,34 @@ pub fn compare(left: &Array, right: &Array, operator: Operator) -> VortexResult<
vortex_bail!("Compare operations only support arrays of the same type");
}

if ConstantArray::try_from(left).is_ok() {
let scalar = scalar_at(left, 0)?;
let left_const = ConstantArray::new(scalar, left.len()).into_array();
return compare(right, &left_const, operator.swap());
use crate::stats::{ArrayStatistics, Stat};

let l_is_const = ConstantArray::try_from(left).is_ok()
|| left
.statistics()
.get_as::<bool>(Stat::IsConstant)
.unwrap_or_default();
let r_is_const = ConstantArray::try_from(right).is_ok()
|| right
.statistics()
.get_as::<bool>(Stat::IsConstant)
.unwrap_or_default();

match (l_is_const, r_is_const) {
(true, false) => {
let scalar = scalar_at(left, 0)?;
let left_const = ConstantArray::new(scalar, left.len()).into_array();
return compare(right, &left_const, operator.swap());
}
(true, true) => {
let original_len = left.len();
let left = scalar_at(left, 0)?;
let right = scalar_at(right, 0)?;
let r = scalar_cmp(&left, &right, operator);
let arr = ConstantArray::new(r, original_len);
return Ok(arr.into_array());
}
(false, true) | (false, false) => {}
}

if let Some(selection) = left.with_dyn(|lhs| lhs.compare(right, operator)) {
Expand Down