-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters