Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
fixed neq_and_validity in the default case w/ nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 8, 2022
1 parent 6c102a0 commit 2dcb35d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/compute/comparison/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,12 @@ fn finish_neq_validities(
if both_sides_invalid.values().unset_bits() != both_sides_invalid.len() {
// we use the `binary` kernel directly to save allocations
// and apply `lhs & !rhs)` in one shot.
compute::boolean::binary_boolean_kernel(&lhs, &rhs, |lhs, rhs| {
binary(lhs, rhs, |lhs, rhs| (lhs & !rhs))
})

compute::boolean::binary_boolean_kernel(
&or,
&both_sides_invalid,
|lhs, rhs| binary(lhs, rhs, |lhs, rhs| (lhs & !rhs)),
)
} else {
or
}
Expand Down
15 changes: 14 additions & 1 deletion tests/it/compute/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ fn primitive_gt_eq() {
}

#[test]
#[cfg(any(feature = "compute_cast", feature = "compute_boolean_kleene"))]
#[cfg(all(feature = "compute_cast", feature = "compute_boolean_kleene"))]
fn utf8_and_validity() {
use arrow2::compute::cast::CastOptions;
let a1 = Utf8Array::<i32>::from([Some("0"), Some("1"), None, Some("2")]);
Expand All @@ -401,3 +401,16 @@ fn utf8_and_validity() {
assert_eq!(utf8::neq_and_validity(&a1, &a1), expected);
assert_eq!(utf8::neq_and_validity(&a1, a2), expected);
}

#[test]
#[cfg(feature = "compute_boolean_kleene")]
fn primitive_and_validity() {
let a1 = Int32Array::from([Some(0), None]);
let a2 = Int32Array::from([Some(10), None]);

let expected = BooleanArray::from_slice([true, false]);
assert_eq!(primitive::neq_and_validity(&a1, &a2), expected);

let expected = BooleanArray::from_slice([false, true]);
assert_eq!(primitive::eq_and_validity(&a1, &a2), expected);
}

0 comments on commit 2dcb35d

Please sign in to comment.