pub trait Array: Debug + Send + Sync + JsonEqual {
Show 14 methods
fn as_any(&self) -> &dyn Any;
fn data(&self) -> &ArrayData;
fn data_ref(&self) -> &ArrayData { ... }
fn data_type(&self) -> &DataType { ... }
fn slice(&self, offset: usize, length: usize) -> ArrayRef { ... }
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 { ... }
fn to_raw(&self) -> Result<(*const FFI_ArrowArray, *const FFI_ArrowSchema)> { ... }
}
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
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");
Provided Methods
Returns a reference-counted pointer to the underlying data of this array.
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]));
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);
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);
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);
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);
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
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);
fn get_buffer_memory_size(&self) -> usize
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.
fn get_array_memory_size(&self) -> usize
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.
fn to_raw(&self) -> Result<(*const FFI_ArrowArray, *const FFI_ArrowSchema)>
fn to_raw(&self) -> Result<(*const FFI_ArrowArray, *const FFI_ArrowSchema)>
returns two pointers that represent this array in the C Data Interface (FFI)
Trait Implementations
Implementors
impl Array for BooleanArray
impl Array for DecimalArray
impl Array for FixedSizeBinaryArray
impl Array for FixedSizeListArray
impl Array for MapArray
impl Array for NullArray
impl Array for StructArray
impl Array for UnionArray
impl Array for ArrayRef
Ergonomics: Allow use of an ArrayRef as an &dyn Array