Module arrow2::compute::comparison

source ·
Available on crate feature compute_comparison only.
Expand description

Contains comparison operators

The module contains functions that compare either an Array and a Scalar or two Arrays (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 or lt_scalar).

Examples

Compare two PrimitiveArrays:

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 Arrays (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
Comparison functions for Utf8Array

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 comparable is supported by eq.
Returns whether a DataType is supported by eq_scalar.
Returns whether a DataType is comparable is supported by gt.
Returns whether a DataType is comparable is supported by gt_eq.
Returns whether a DataType is supported by gt_eq_scalar.
Returns whether a DataType is supported by gt_scalar.
Returns whether a DataType is comparable is supported by lt.
Returns whether a DataType is comparable is supported by lt.
Returns whether a DataType is supported by lt_eq_scalar.
Returns whether a DataType is supported by lt_scalar.
Returns whether a DataType is comparable is supported by neq.
Returns whether a DataType is supported by neq_scalar.
== between two Arrays. Use can_eq to check whether the operation is valid
== between two Arrays and includes validities in comparison. Use can_eq to check whether the operation is valid
== 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
Utility for low level end users that implement their own comparison functions A comparison on the data column can be applied on masked out values This function will correct equality for the validities.
Utility for low level end users that implement their own comparison functions A comparison on the data column can be applied on masked out values This function will correct non-equality for the validities.
> between two Arrays. Use can_gt to check whether the operation is valid
>= between two Arrays. Use can_gt_eq 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 two Arrays. Use can_lt to check whether the operation is valid
<= between two Arrays. Use can_lt_eq 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 two Arrays. Use can_neq to check whether the operation is valid
!= between two Arrays and includes validities in comparison. Use can_neq 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