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

Traits

Functions