Trait arrow::array::Array

source ·
pub trait Array: Debug + Send + Sync {
Show 14 methods // Required methods fn as_any(&self) -> &(dyn Any + 'static); fn data(&self) -> &ArrayData; fn into_data(self) -> ArrayData; // Provided methods fn data_ref(&self) -> &ArrayData { ... } fn data_type(&self) -> &DataType { ... } fn slice(&self, offset: usize, length: usize) -> Arc<dyn Array + 'static> { ... } fn len(&self) -> usize { ... } fn is_empty(&self) -> bool { ... } fn offset(&self) -> usize { ... } fn is_null(&self, index: usize) -> bool { ... } fn is_valid(&self, index: usize) -> bool { ... } fn null_count(&self) -> usize { ... } fn get_buffer_memory_size(&self) -> usize { ... } fn get_array_memory_size(&self) -> usize { ... }
}
Expand description

Trait for dealing with different types of array at runtime when the type of the array is not known in advance.

Required Methods§

source

fn as_any(&self) -> &(dyn Any + 'static)

Returns the array as Any so that it can be downcasted to a specific implementation.

Example:

let id = Int32Array::from(vec![1, 2, 3, 4, 5]);
let batch = RecordBatch::try_new(
    Arc::new(Schema::new(vec![Field::new("id", DataType::Int32, false)])),
    vec![Arc::new(id)]
).unwrap();

let int32array = batch
    .column(0)
    .as_any()
    .downcast_ref::<Int32Array>()
    .expect("Failed to downcast");
source

fn data(&self) -> &ArrayData

Returns a reference to the underlying data of this array.

source

fn into_data(self) -> ArrayData

Returns the underlying data of this array.

Provided Methods§

source

fn data_ref(&self) -> &ArrayData

Returns a reference-counted pointer to the underlying data of this array.

source

fn data_type(&self) -> &DataType

Returns a reference to the DataType of this array.

Example:
use arrow_schema::DataType;
use arrow_array::{Array, Int32Array};

let array = Int32Array::from(vec![1, 2, 3, 4, 5]);

assert_eq!(*array.data_type(), DataType::Int32);
source

fn slice(&self, offset: usize, length: usize) -> Arc<dyn Array + 'static>

Returns a zero-copy slice of this array with the indicated offset and length.

Example:
use arrow_array::{Array, Int32Array};

let array = Int32Array::from(vec![1, 2, 3, 4, 5]);
// Make slice over the values [2, 3, 4]
let array_slice = array.slice(1, 3);

assert_eq!(array_slice.as_ref(), &Int32Array::from(vec![2, 3, 4]));
source

fn len(&self) -> usize

Returns the length (i.e., number of elements) of this array.

Example:
use arrow_array::{Array, Int32Array};

let array = Int32Array::from(vec![1, 2, 3, 4, 5]);

assert_eq!(array.len(), 5);
source

fn is_empty(&self) -> bool

Returns whether this array is empty.

Example:
use arrow_array::{Array, Int32Array};

let array = Int32Array::from(vec![1, 2, 3, 4, 5]);

assert_eq!(array.is_empty(), false);
source

fn offset(&self) -> usize

Returns the offset into the underlying data used by this array(-slice). Note that the underlying data can be shared by many arrays. This defaults to 0.

Example:
use arrow_array::{Array, Int32Array};

let array = Int32Array::from(vec![1, 2, 3, 4, 5]);
// Make slice over the values [2, 3, 4]
let array_slice = array.slice(1, 3);

assert_eq!(array.offset(), 0);
assert_eq!(array_slice.offset(), 1);
source

fn is_null(&self, index: usize) -> bool

Returns whether the element at index is null. When using this function on a slice, the index is relative to the slice.

Example:
use arrow_array::{Array, Int32Array};

let array = Int32Array::from(vec![Some(1), None]);

assert_eq!(array.is_null(0), false);
assert_eq!(array.is_null(1), true);
source

fn is_valid(&self, index: usize) -> bool

Returns whether the element at index is not null. When using this function on a slice, the index is relative to the slice.

Example:
use arrow_array::{Array, Int32Array};

let array = Int32Array::from(vec![Some(1), None]);

assert_eq!(array.is_valid(0), true);
assert_eq!(array.is_valid(1), false);
source

fn null_count(&self) -> usize

Returns the total number of null values in this array.

Example:
use arrow_array::{Array, Int32Array};

// Construct an array with values [1, NULL, NULL]
let array = Int32Array::from(vec![Some(1), None, None]);

assert_eq!(array.null_count(), 2);
source

fn get_buffer_memory_size(&self) -> usize

Returns the total number of bytes of memory pointed to by this array. The buffers store bytes in the Arrow memory format, and include the data as well as the validity map.

source

fn get_array_memory_size(&self) -> usize

Returns the total number of bytes of memory occupied physically by this array. This value will always be greater than returned by get_buffer_memory_size() and includes the overhead of the data structures that contain the pointers to the various buffers.

Trait Implementations§

source§

impl<T> PartialEq<T> for dyn Array + 'staticwhere T: Array,

source§

fn eq(&self, other: &T) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<dyn Array + 'static> for dyn Array + 'static

source§

fn eq(&self, other: &(dyn Array + 'static)) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Implementations on Foreign Types§

source§

impl<'a, T> Array for &'a Twhere T: Array,

source§

fn as_any(&self) -> &(dyn Any + 'static)

source§

fn data(&self) -> &ArrayData

source§

fn into_data(self) -> ArrayData

source§

fn data_ref(&self) -> &ArrayData

source§

fn data_type(&self) -> &DataType

source§

fn slice(&self, offset: usize, length: usize) -> Arc<dyn Array + 'static>

source§

fn len(&self) -> usize

source§

fn is_empty(&self) -> bool

source§

fn offset(&self) -> usize

source§

fn is_null(&self, index: usize) -> bool

source§

fn is_valid(&self, index: usize) -> bool

source§

fn null_count(&self) -> usize

source§

fn get_buffer_memory_size(&self) -> usize

source§

fn get_array_memory_size(&self) -> usize

source§

impl Array for Arc<dyn Array + 'static>

Ergonomics: Allow use of an ArrayRef as an &dyn Array

source§

fn as_any(&self) -> &(dyn Any + 'static)

source§

fn data(&self) -> &ArrayData

source§

fn into_data(self) -> ArrayData

source§

fn data_ref(&self) -> &ArrayData

source§

fn data_type(&self) -> &DataType

source§

fn slice(&self, offset: usize, length: usize) -> Arc<dyn Array + 'static>

source§

fn len(&self) -> usize

source§

fn is_empty(&self) -> bool

source§

fn offset(&self) -> usize

source§

fn is_null(&self, index: usize) -> bool

source§

fn is_valid(&self, index: usize) -> bool

source§

fn null_count(&self) -> usize

source§

fn get_buffer_memory_size(&self) -> usize

source§

fn get_array_memory_size(&self) -> usize

Implementors§