Module arrow_cast::cast

source ·
Expand description

Defines cast kernels for ArrayRef, to convert Arrays between supported datatypes.

Example:

use arrow_array::*;
use arrow_cast::cast;
use arrow_schema::DataType;
use std::sync::Arc;
use arrow_array::types::Float64Type;
use arrow_array::cast::AsArray;

let a = Int32Array::from(vec![5, 6, 7]);
let array = Arc::new(a) as ArrayRef;
let b = cast(&array, &DataType::Float64).unwrap();
let c = b.as_primitive::<Float64Type>();
assert_eq!(5.0, c.value(0));
assert_eq!(6.0, c.value(1));
assert_eq!(7.0, c.value(2));

Structs

  • CastOptions provides a way to override the default cast behaviors

Functions

  • Return true if a value of type from_type can be cast into a value of to_type. Note that such as cast may be lossy.
  • Cast array to the provided data type and return a new Array with type to_type, if possible.
  • Cast array to the provided data type and return a new Array with type to_type, if possible. It accepts CastOptions to allow consumers to configure cast behavior.