Function arrow_array::cast::as_primitive_array

source ·
pub fn as_primitive_array<T>(arr: &dyn Array) -> &PrimitiveArray<T>
Expand description

Force downcast of an Array, such as an ArrayRef, to PrimitiveArray<T>, panic’ing on failure.

§Example


let arr: ArrayRef = Arc::new(Int32Array::from(vec![Some(1)]));

// Downcast an `ArrayRef` to Int32Array / PrimitiveArray<Int32>:
let primitive_array: &Int32Array = as_primitive_array(&arr);

// Equivalently:
let primitive_array = as_primitive_array::<Int32Type>(&arr);

// This is the equivalent of:
let primitive_array = arr
    .as_any()
    .downcast_ref::<Int32Array>()
    .unwrap();