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

Commit

Permalink
expose for &dyn array
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Feb 16, 2022
1 parent a9bc92d commit 89185f0
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/compute/comparison/binary.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Comparison functions for [`BinaryArray`]
use crate::compute::comparison::{eq_validities, neq_validities};
use crate::compute::comparison::{finish_eq_validities, finish_neq_validities};
use crate::{
array::{BinaryArray, BooleanArray, Offset},
bitmap::Bitmap,
Expand Down Expand Up @@ -60,7 +60,7 @@ pub fn eq_and_validity<O: Offset>(lhs: &BinaryArray<O>, rhs: &BinaryArray<O>) ->
let rhs = rhs.with_validity(None);
let out = compare_op(&lhs, &rhs, |a, b| a == b);

eq_validities(out, validity_lhs, validity_rhs)
finish_eq_validities(out, validity_lhs, validity_rhs)
}

/// Perform `lhs == rhs` operation on [`BinaryArray`] and a scalar.
Expand All @@ -74,7 +74,7 @@ pub fn eq_scalar_and_validity<O: Offset>(lhs: &BinaryArray<O>, rhs: &[u8]) -> Bo
let lhs = lhs.with_validity(None);
let out = compare_op_scalar(&lhs, rhs, |a, b| a == b);

eq_validities(out, validity, None)
finish_eq_validities(out, validity, None)
}

/// Perform `lhs != rhs` operation on [`BinaryArray`].
Expand All @@ -94,7 +94,7 @@ pub fn neq_and_validity<O: Offset>(lhs: &BinaryArray<O>, rhs: &BinaryArray<O>) -
let rhs = rhs.with_validity(None);

let out = compare_op(&lhs, &rhs, |a, b| a != b);
neq_validities(out, validity_lhs, validity_rhs)
finish_neq_validities(out, validity_lhs, validity_rhs)
}

/// Perform `lhs != rhs` operation on [`BinaryArray`] and a scalar.
Expand All @@ -108,7 +108,7 @@ pub fn neq_scalar_and_validity<O: Offset>(lhs: &BinaryArray<O>, rhs: &[u8]) -> B
let lhs = lhs.with_validity(None);
let out = compare_op_scalar(&lhs, rhs, |a, b| a != b);

neq_validities(out, validity, None)
finish_neq_validities(out, validity, None)
}

/// Perform `lhs < rhs` operation on [`BinaryArray`].
Expand Down
12 changes: 6 additions & 6 deletions src/compute/comparison/boolean.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Comparison functions for [`BooleanArray`]
use crate::compute::comparison::{eq_validities, neq_validities};
use crate::compute::comparison::{finish_eq_validities, finish_neq_validities};
use crate::{
array::BooleanArray,
bitmap::{binary, unary, Bitmap},
Expand Down Expand Up @@ -47,7 +47,7 @@ pub fn eq_and_validity(lhs: &BooleanArray, rhs: &BooleanArray) -> BooleanArray {
let rhs = rhs.with_validity(None);
let out = compare_op(&lhs, &rhs, |a, b| !(a ^ b));

eq_validities(out, validity_lhs, validity_rhs)
finish_eq_validities(out, validity_lhs, validity_rhs)
}

/// Perform `lhs == rhs` operation on a [`BooleanArray`] and a scalar value.
Expand All @@ -64,13 +64,13 @@ pub fn eq_scalar_and_validity(lhs: &BooleanArray, rhs: bool) -> BooleanArray {
let validity = lhs.validity().cloned();
let lhs = lhs.with_validity(None);
if rhs {
eq_validities(lhs, validity, None)
finish_eq_validities(lhs, validity, None)
} else {
let lhs = lhs.with_validity(None);

let out = compare_op_scalar(&lhs, rhs, |a, _| !a);

eq_validities(out, validity, None)
finish_eq_validities(out, validity, None)
}
}

Expand All @@ -87,7 +87,7 @@ pub fn neq_and_validity(lhs: &BooleanArray, rhs: &BooleanArray) -> BooleanArray
let rhs = rhs.with_validity(None);
let out = compare_op(&lhs, &rhs, |a, b| a ^ b);

neq_validities(out, validity_lhs, validity_rhs)
finish_neq_validities(out, validity_lhs, validity_rhs)
}

/// Perform `left != right` operation on an array and a scalar value.
Expand All @@ -100,7 +100,7 @@ pub fn neq_scalar_and_validity(lhs: &BooleanArray, rhs: bool) -> BooleanArray {
let validity = lhs.validity().cloned();
let lhs = lhs.with_validity(None);
let out = eq_scalar(&lhs, !rhs);
neq_validities(out, validity, None)
finish_neq_validities(out, validity, None)
}

/// Perform `left < right` operation on two arrays.
Expand Down
46 changes: 44 additions & 2 deletions src/compute/comparison/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ pub fn eq(lhs: &dyn Array, rhs: &dyn Array) -> BooleanArray {
compare!(lhs, rhs, eq, match_eq)
}

/// `==` between two [`Array`]s and includes validities in comparison.
/// Use [`can_eq`] to check whether the operation is valid
/// # Panic
/// Panics iff either:
/// * the arrays do not have have the same logical type
/// * the arrays do not have the same length
/// * the operation is not supported for the logical type
pub fn eq_and_validity(lhs: &dyn Array, rhs: &dyn Array) -> BooleanArray {
compare!(lhs, rhs, eq_and_validity, match_eq)
}

/// Returns whether a [`DataType`] is comparable is supported by [`eq`].
pub fn can_eq(data_type: &DataType) -> bool {
can_partial_eq(data_type)
Expand All @@ -185,6 +196,17 @@ pub fn neq(lhs: &dyn Array, rhs: &dyn Array) -> BooleanArray {
compare!(lhs, rhs, neq, match_eq)
}

/// `!=` between two [`Array`]s and includes validities in comparison.
/// Use [`can_neq`] to check whether the operation is valid
/// # Panic
/// Panics iff either:
/// * the arrays do not have have the same logical type
/// * the arrays do not have the same length
/// * the operation is not supported for the logical type
pub fn neq_and_validity(lhs: &dyn Array, rhs: &dyn Array) -> BooleanArray {
compare!(lhs, rhs, neq_and_validity, match_eq)
}

/// Returns whether a [`DataType`] is comparable is supported by [`neq`].
pub fn can_neq(data_type: &DataType) -> bool {
can_partial_eq(data_type)
Expand Down Expand Up @@ -322,6 +344,16 @@ pub fn eq_scalar(lhs: &dyn Array, rhs: &dyn Scalar) -> BooleanArray {
compare_scalar!(lhs, rhs, eq_scalar, match_eq)
}

/// `==` between an [`Array`] and a [`Scalar`] and includes validities in comparison.
/// Use [`can_eq_scalar`] to check whether the operation is valid
/// # Panic
/// Panics iff either:
/// * they do not have have the same logical type
/// * the operation is not supported for the logical type
pub fn eq_scalar_and_validity(lhs: &dyn Array, rhs: &dyn Scalar) -> BooleanArray {
compare_scalar!(lhs, rhs, eq_scalar_and_validity, match_eq)
}

/// Returns whether a [`DataType`] is supported by [`eq_scalar`].
pub fn can_eq_scalar(data_type: &DataType) -> bool {
can_partial_eq_scalar(data_type)
Expand All @@ -337,6 +369,16 @@ pub fn neq_scalar(lhs: &dyn Array, rhs: &dyn Scalar) -> BooleanArray {
compare_scalar!(lhs, rhs, neq_scalar, match_eq)
}

/// `!=` between an [`Array`] and a [`Scalar`] and includes validities in comparison.
/// Use [`can_neq_scalar`] to check whether the operation is valid
/// # Panic
/// Panics iff either:
/// * they do not have have the same logical type
/// * the operation is not supported for the logical type
pub fn neq_scalar_and_validty(lhs: &dyn Array, rhs: &dyn Scalar) -> BooleanArray {
compare_scalar!(lhs, rhs, neq_scalar_and_validity, match_eq)
}

/// Returns whether a [`DataType`] is supported by [`neq_scalar`].
pub fn can_neq_scalar(data_type: &DataType) -> bool {
can_partial_eq_scalar(data_type)
Expand Down Expand Up @@ -460,7 +502,7 @@ fn can_partial_eq_scalar(data_type: &DataType) -> bool {
)
}

fn eq_validities(
fn finish_eq_validities(
output_without_validities: BooleanArray,
validity_lhs: Option<Bitmap>,
validity_rhs: Option<Bitmap>,
Expand All @@ -485,7 +527,7 @@ fn eq_validities(
}
}
}
fn neq_validities(
fn finish_neq_validities(
output_without_validities: BooleanArray,
validity_lhs: Option<Bitmap>,
validity_rhs: Option<Bitmap>,
Expand Down
10 changes: 5 additions & 5 deletions src/compute/comparison/primitive.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Comparison functions for [`PrimitiveArray`]
use crate::compute::comparison::{eq_validities, neq_validities};
use crate::compute::comparison::{finish_eq_validities, finish_neq_validities};
use crate::{
array::{BooleanArray, PrimitiveArray},
bitmap::MutableBitmap,
Expand Down Expand Up @@ -112,7 +112,7 @@ where
let rhs = rhs.with_validity(None);
let out = compare_op(&lhs, &rhs, |a, b| a.eq(b));

eq_validities(out, validity_lhs, validity_rhs)
finish_eq_validities(out, validity_lhs, validity_rhs)
}

/// Perform `left == right` operation on an array and a scalar value.
Expand All @@ -134,7 +134,7 @@ where
let lhs = lhs.with_validity(None);
let out = compare_op_scalar(&lhs, rhs, |a, b| a.eq(b));

eq_validities(out, validity, None)
finish_eq_validities(out, validity, None)
}

/// Perform `left != right` operation on two arrays.
Expand All @@ -158,7 +158,7 @@ where
let rhs = rhs.with_validity(None);
let out = compare_op(&lhs, &rhs, |a, b| a.neq(b));

neq_validities(out, validity_lhs, validity_rhs)
finish_neq_validities(out, validity_lhs, validity_rhs)
}

/// Perform `left != right` operation on an array and a scalar value.
Expand All @@ -180,7 +180,7 @@ where
let lhs = lhs.with_validity(None);
let out = compare_op_scalar(&lhs, rhs, |a, b| a.neq(b));

neq_validities(out, validity, None)
finish_neq_validities(out, validity, None)
}

/// Perform `left < right` operation on two arrays.
Expand Down
10 changes: 5 additions & 5 deletions src/compute/comparison/utf8.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Comparison functions for [`Utf8Array`]
use crate::compute::comparison::{eq_validities, neq_validities};
use crate::compute::comparison::{finish_eq_validities, finish_neq_validities};
use crate::{
array::{BooleanArray, Offset, Utf8Array},
bitmap::Bitmap,
Expand Down Expand Up @@ -55,7 +55,7 @@ pub fn eq_and_validity<O: Offset>(lhs: &Utf8Array<O>, rhs: &Utf8Array<O>) -> Boo
let rhs = rhs.with_validity(None);
let out = compare_op(&lhs, &rhs, |a, b| a == b);

eq_validities(out, validity_lhs, validity_rhs)
finish_eq_validities(out, validity_lhs, validity_rhs)
}

/// Perform `lhs != rhs` operation on [`Utf8Array`] and include validities in comparison.
Expand All @@ -66,7 +66,7 @@ pub fn neq_and_validity<O: Offset>(lhs: &Utf8Array<O>, rhs: &Utf8Array<O>) -> Bo
let rhs = rhs.with_validity(None);
let out = compare_op(&lhs, &rhs, |a, b| a != b);

neq_validities(out, validity_lhs, validity_rhs)
finish_neq_validities(out, validity_lhs, validity_rhs)
}

/// Perform `lhs == rhs` operation on [`Utf8Array`] and a scalar.
Expand All @@ -80,7 +80,7 @@ pub fn eq_scalar_and_validity<O: Offset>(lhs: &Utf8Array<O>, rhs: &str) -> Boole
let lhs = lhs.with_validity(None);
let out = compare_op_scalar(&lhs, rhs, |a, b| a == b);

eq_validities(out, validity, None)
finish_eq_validities(out, validity, None)
}

/// Perform `lhs != rhs` operation on [`Utf8Array`] and a scalar. Also includes null values in comparisson.
Expand All @@ -89,7 +89,7 @@ pub fn neq_scalar_and_validity<O: Offset>(lhs: &Utf8Array<O>, rhs: &str) -> Bool
let lhs = lhs.with_validity(None);
let out = compare_op_scalar(&lhs, rhs, |a, b| a != b);

neq_validities(out, validity, None)
finish_neq_validities(out, validity, None)
}

/// Perform `lhs != rhs` operation on [`Utf8Array`].
Expand Down

0 comments on commit 89185f0

Please sign in to comment.