[−][src]Trait arrow::array::Array
Trait for dealing with different types of array at runtime when the type of the array is not known in advance.
Required methods
fn as_any(&self) -> &dyn Any
Returns the array as Any
so that it can be
downcasted to a specific implementation.
Example:
use std::sync::Arc; use arrow::array::Int32Array; use arrow::datatypes::{Schema, Field, DataType}; use arrow::record_batch::RecordBatch; 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)] )?; let int32array = batch .column(0) .as_any() .downcast_ref::<Int32Array>() .expect("Failed to downcast");
fn data(&self) -> ArrayDataRef
Returns a reference-counted pointer to the underlying data of this array.
fn data_ref(&self) -> &ArrayDataRef
Returns a borrowed & reference-counted pointer to the underlying data of this array.
Provided methods
fn data_type(&self) -> &DataType
Returns a reference to the DataType
of this array.
Example:
use arrow::datatypes::DataType; use arrow::array::{Array, Int32Array}; let array = Int32Array::from(vec![1, 2, 3, 4, 5]); assert_eq!(*array.data_type(), DataType::Int32);
fn slice(&self, offset: usize, length: usize) -> ArrayRef
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!(array_slice.equals(&Int32Array::from(vec![2, 3, 4])));
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);
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);
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);
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);
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);
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);
Implementors
impl Array for BinaryArray
[src]
fn as_any(&self) -> &dyn Any
[src]
fn data(&self) -> ArrayDataRef
[src]
fn data_ref(&self) -> &ArrayDataRef
[src]
impl Array for FixedSizeBinaryArray
[src]
fn as_any(&self) -> &dyn Any
[src]
fn data(&self) -> ArrayDataRef
[src]
fn data_ref(&self) -> &ArrayDataRef
[src]
impl Array for FixedSizeListArray
[src]
fn as_any(&self) -> &dyn Any
[src]
fn data(&self) -> ArrayDataRef
[src]
fn data_ref(&self) -> &ArrayDataRef
[src]
impl Array for LargeBinaryArray
[src]
fn as_any(&self) -> &dyn Any
[src]
fn data(&self) -> ArrayDataRef
[src]
fn data_ref(&self) -> &ArrayDataRef
[src]
impl Array for LargeListArray
[src]
fn as_any(&self) -> &dyn Any
[src]
fn data(&self) -> ArrayDataRef
[src]
fn data_ref(&self) -> &ArrayDataRef
[src]
impl Array for LargeStringArray
[src]
fn as_any(&self) -> &dyn Any
[src]
fn data(&self) -> ArrayDataRef
[src]
fn data_ref(&self) -> &ArrayDataRef
[src]
impl Array for ListArray
[src]
fn as_any(&self) -> &dyn Any
[src]
fn data(&self) -> ArrayDataRef
[src]
fn data_ref(&self) -> &ArrayDataRef
[src]
impl Array for NullArray
[src]
fn as_any(&self) -> &dyn Any
[src]
fn data(&self) -> ArrayDataRef
[src]
fn data_ref(&self) -> &ArrayDataRef
[src]
fn is_null(&self, _index: usize) -> bool
[src]
Returns whether the element at index
is null.
All elements of a NullArray
are always null.
fn is_valid(&self, _index: usize) -> bool
[src]
Returns whether the element at index
is valid.
All elements of a NullArray
are always invalid.
fn null_count(&self) -> usize
[src]
Returns the total number of null values in this array.
The null count of a NullArray
always equals its length.
impl Array for StringArray
[src]
fn as_any(&self) -> &dyn Any
[src]
fn data(&self) -> ArrayDataRef
[src]
fn data_ref(&self) -> &ArrayDataRef
[src]
impl Array for StructArray
[src]
fn as_any(&self) -> &dyn Any
[src]
fn data(&self) -> ArrayDataRef
[src]
fn data_ref(&self) -> &ArrayDataRef
[src]
fn len(&self) -> usize
[src]
Returns the length (i.e., number of elements) of this array