Module arrow2::compute::comparison
source · [−]Expand description
Contains comparison operators
The module contains functions that compare either an Array
and a Scalar
or two Array
s (of the same DataType
). The scalar-oriented functions are
suffixed with _scalar
.
The functions are organized in two variants:
- statically typed
- dynamically typed
The statically typed are available under each module of this module (e.g.
primitive::eq
,primitive::lt_scalar
) The dynamically typed are available in this module (e.g.eq
orlt_scalar
).
Examples
Compare two PrimitiveArray
s:
use arrow2::array::{BooleanArray, PrimitiveArray};
use arrow2::compute::comparison::primitive::gt;
let array1 = PrimitiveArray::<i32>::from([Some(1), None, Some(2)]);
let array2 = PrimitiveArray::<i32>::from([Some(1), Some(3), Some(1)]);
let result = gt(&array1, &array2);
assert_eq!(result, BooleanArray::from([Some(false), None, Some(true)]));
Compare two dynamically-typed Array
s (trait objects):
use arrow2::array::{Array, BooleanArray, PrimitiveArray};
use arrow2::compute::comparison::eq;
let array1: &dyn Array = &PrimitiveArray::<f64>::from(&[Some(10.0), None, Some(20.0)]);
let array2: &dyn Array = &PrimitiveArray::<f64>::from(&[Some(10.0), None, Some(10.0)]);
let result = eq(array1, array2);
assert_eq!(result, BooleanArray::from([Some(true), None, Some(false)]));
Compare (not equal) a Utf8Array
to a word:
use arrow2::array::{BooleanArray, Utf8Array};
use arrow2::compute::comparison::utf8::neq_scalar;
let array = Utf8Array::<i32>::from([Some("compute"), None, Some("compare")]);
let result = neq_scalar(&array, "compare");
assert_eq!(result, BooleanArray::from([Some(true), None, Some(false)]));
Modules
Comparison functions for BinaryArray
Comparison functions for BooleanArray
Comparison functions for PrimitiveArray
Traits
NativeType
that supports a representation of 8 lanes
Trait declaring an 8-lane multi-data.
Trait implemented by implementors of Simd8Lanes
whose Simd8
implements PartialEq.
Trait implemented by implementors of Simd8Lanes
whose Simd8
implements PartialOrd.
Functions
Returns whether a DataType
is supported by gt_eq_scalar
.
Returns whether a DataType
is supported by lt_eq_scalar
.
Returns whether a DataType
is supported by neq_scalar
.
==
between an Array
and a Scalar
.
Use can_eq_scalar
to check whether the operation is valid
==
between an Array
and a Scalar
and includes validities in comparison.
Use can_eq_scalar
to check whether the operation is valid
>=
between an Array
and a Scalar
.
Use can_gt_eq_scalar
to check whether the operation is valid
>
between an Array
and a Scalar
.
Use can_gt_scalar
to check whether the operation is valid
<=
between an Array
and a Scalar
.
Use can_lt_eq_scalar
to check whether the operation is valid
<
between an Array
and a Scalar
.
Use can_lt_scalar
to check whether the operation is valid
!=
between an Array
and a Scalar
.
Use can_neq_scalar
to check whether the operation is valid
!=
between an Array
and a Scalar
and includes validities in comparison.
Use can_neq_scalar
to check whether the operation is valid