Skip to content

Commit

Permalink
for compare
Browse files Browse the repository at this point in the history
  • Loading branch information
doki23 committed Dec 5, 2024
1 parent 0942d55 commit a94f598
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions encodings/fastlanes/src/for/compare.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use vortex_array::compute::{compare, CompareFn, Operator};
use vortex_array::ArrayData;
use vortex_error::VortexResult;

use crate::{decompress, FoRArray, FoREncoding};

impl CompareFn<FoRArray> for FoREncoding {
fn compare(
&self,
lhs: &FoRArray,
rhs: &ArrayData,
operator: Operator,
) -> VortexResult<Option<ArrayData>> {
// this is cheap
let owned_lhs = lhs.clone();
let decompressed_lhs = decompress(owned_lhs)?;
compare(decompressed_lhs, rhs, operator).map(|array_data| Some(array_data))
}
}

#[cfg(test)]
mod tests {
use vortex_array::array::PrimitiveArray;
use vortex_array::compute::{compare, Operator};
use vortex_array::validity::Validity;
use vortex_array::IntoArrayVariant;

use crate::for_compress;

#[test]
fn test_for_compare() {
let lhs = PrimitiveArray::from_vec(vec![1i32, 2, 3, 4, 5], Validity::AllValid);
let lhs = for_compress(&lhs).unwrap();
let rhs = PrimitiveArray::from_vec(vec![1i32, 2, 9, 4, 5], Validity::AllValid);
assert_eq!(
compare(lhs, rhs, Operator::Eq)
.unwrap()
.into_bool()
.unwrap()
.boolean_buffer(),
vec![true, true, false, true, true].into()
);
}
}
1 change: 1 addition & 0 deletions encodings/fastlanes/src/for/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use vortex_dtype::DType;
use vortex_error::{vortex_bail, VortexExpect as _, VortexResult};
use vortex_scalar::{Scalar, ScalarValue};

mod compare;
mod compress;
mod compute;

Expand Down

0 comments on commit a94f598

Please sign in to comment.