arrow::array::array

Trait Array

pub trait Array:
    Debug
    + Send
    + Sync {
Show 18 methods // Required methods fn as_any(&self) -> &(dyn Any + 'static); fn to_data(&self) -> ArrayData; fn into_data(self) -> ArrayData; fn data_type(&self) -> &DataType; fn slice(&self, offset: usize, length: usize) -> Arc<dyn Array>; fn len(&self) -> usize; fn is_empty(&self) -> bool; fn offset(&self) -> usize; fn nulls(&self) -> Option<&NullBuffer>; fn get_buffer_memory_size(&self) -> usize; fn get_array_memory_size(&self) -> usize; // Provided methods fn shrink_to_fit(&mut self) { ... } fn logical_nulls(&self) -> Option<NullBuffer> { ... } fn is_null(&self, index: usize) -> bool { ... } fn is_valid(&self, index: usize) -> bool { ... } fn null_count(&self) -> usize { ... } fn logical_null_count(&self) -> usize { ... } fn is_nullable(&self) -> bool { ... }
}
Expand description

An array in the arrow columnar format

Required Methods§

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");

fn to_data(&self) -> ArrayData

Returns the underlying data of this array

fn into_data(self) -> ArrayData

Returns the underlying data of this array

Unlike Array::to_data this consumes self, allowing it avoid unnecessary clones

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);

fn slice(&self, offset: usize, length: usize) -> Arc<dyn 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, &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, BooleanArray};

let array = BooleanArray::from(vec![false, false, true, true]);
let array_slice = array.slice(1, 3);

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

fn nulls(&self) -> Option<&NullBuffer>

Returns the null buffer of this array if any.

The null buffer contains the “physical” nulls of an array, that is how the nulls are represented in the underlying arrow format.

The physical representation is efficient, but is sometimes non intuitive for certain array types such as those with nullable child arrays like DictionaryArray::values, RunArray::values or UnionArray, or without a null buffer, such as NullArray.

To determine if each element of such an array is “logically” null, use the slower Array::logical_nulls to obtain a computed mask.

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. Note that this does not always correspond to the exact memory usage of an array, since multiple arrays can share the same buffers or slices thereof.

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.

Provided Methods§

fn shrink_to_fit(&mut self)

Shrinks the capacity of any exclusively owned buffer as much as possible

Shared or externally allocated buffers will be ignored, and any buffer offsets will be preserved.

fn logical_nulls(&self) -> Option<NullBuffer>

Returns a potentially computed NullBuffer that represents the logical null values of this array, if any.

Logical nulls represent the values that are null in the array, regardless of the underlying physical arrow representation.

For most array types, this is equivalent to the “physical” nulls returned by Array::nulls. It is different for the following cases, because which elements are null is not encoded in a single null buffer:

In these cases a logical NullBuffer will be computed, encoding the logical nullability of these arrays, beyond what is encoded in Array::nulls

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

Returns whether the element at index is null according to Array::nulls

Note: For performance reasons, this method returns nullability solely as determined by the null buffer. This difference can lead to surprising results, for example, NullArray::is_null always returns false as the array lacks a null buffer. Similarly DictionaryArray, RunArray and UnionArray may encode nullability in their children. See Self::logical_nulls for more information.

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

let array = Int32Array::from(vec![Some(1), None]);
assert_eq!(array.is_null(0), false);
assert_eq!(array.is_null(1), true);

// NullArrays do not have a null buffer, and therefore always
// return false for is_null.
let array = NullArray::new(1);
assert_eq!(array.is_null(0), false);

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

Returns whether the element at index is not null, the opposite of Self::is_null.

§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 physical null values in this array.

Note: this method returns the physical null count, i.e. that encoded in Array::nulls, see Array::logical_nulls for logical nullability

§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 logical_null_count(&self) -> usize

Returns the total number of logical null values in this array.

Note: this method returns the logical null count, i.e. that encoded in Array::logical_nulls. In general this is equivalent to Array::null_count but may differ in the presence of logical nullability, see Array::nulls and Array::logical_nulls.

§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.logical_null_count(), 2);

fn is_nullable(&self) -> bool

Returns false if the array is guaranteed to not contain any logical nulls

This is generally equivalent to Array::logical_null_count() != 0 unless determining the logical nulls is expensive, in which case this method can return true even for an array without nulls.

This is also generally equivalent to Array::null_count() != 0 but may differ in the presence of logical nullability, see Array::logical_null_count and Array::null_count.

Implementations will return true unless they can cheaply prove no logical nulls are present. For example a DictionaryArray with nullable values will still return true, even if the nulls present in DictionaryArray::values are not referenced by any key, and therefore would not appear in Array::logical_nulls.

Trait Implementations§

§

impl AsArray for dyn Array + '_

§

fn as_boolean_opt(&self) -> Option<&BooleanArray>

Downcast this to a BooleanArray returning None if not possible
§

fn as_primitive_opt<T>(&self) -> Option<&PrimitiveArray<T>>

Downcast this to a PrimitiveArray returning None if not possible
§

fn as_bytes_opt<T>(&self) -> Option<&GenericByteArray<T>>
where T: ByteArrayType,

Downcast this to a GenericByteArray returning None if not possible
§

fn as_byte_view_opt<T>(&self) -> Option<&GenericByteViewArray<T>>
where T: ByteViewType,

Downcast this to a GenericByteViewArray returning None if not possible
§

fn as_struct_opt(&self) -> Option<&StructArray>

Downcast this to a StructArray returning None if not possible
§

fn as_union_opt(&self) -> Option<&UnionArray>

Downcast this to a UnionArray returning None if not possible
§

fn as_list_opt<O>(&self) -> Option<&GenericListArray<O>>
where O: OffsetSizeTrait,

Downcast this to a GenericListArray returning None if not possible
§

fn as_fixed_size_binary_opt(&self) -> Option<&FixedSizeBinaryArray>

Downcast this to a FixedSizeBinaryArray returning None if not possible
§

fn as_fixed_size_list_opt(&self) -> Option<&FixedSizeListArray>

Downcast this to a FixedSizeListArray returning None if not possible
§

fn as_map_opt(&self) -> Option<&MapArray>

Downcast this to a MapArray returning None if not possible
§

fn as_dictionary_opt<K>(&self) -> Option<&DictionaryArray<K>>

Downcast this to a DictionaryArray returning None if not possible
§

fn as_any_dictionary_opt(&self) -> Option<&dyn AnyDictionaryArray>

Downcasts this to a AnyDictionaryArray returning None if not possible
§

fn as_boolean(&self) -> &BooleanArray

Downcast this to a BooleanArray panicking if not possible
§

fn as_primitive<T>(&self) -> &PrimitiveArray<T>

Downcast this to a PrimitiveArray panicking if not possible
§

fn as_bytes<T>(&self) -> &GenericByteArray<T>
where T: ByteArrayType,

Downcast this to a GenericByteArray panicking if not possible
§

fn as_string_opt<O>(&self) -> Option<&GenericByteArray<GenericStringType<O>>>
where O: OffsetSizeTrait,

Downcast this to a GenericStringArray returning None if not possible
§

fn as_string<O>(&self) -> &GenericByteArray<GenericStringType<O>>
where O: OffsetSizeTrait,

Downcast this to a GenericStringArray panicking if not possible
§

fn as_binary_opt<O>(&self) -> Option<&GenericByteArray<GenericBinaryType<O>>>
where O: OffsetSizeTrait,

Downcast this to a GenericBinaryArray returning None if not possible
§

fn as_binary<O>(&self) -> &GenericByteArray<GenericBinaryType<O>>
where O: OffsetSizeTrait,

Downcast this to a GenericBinaryArray panicking if not possible
§

fn as_string_view_opt(&self) -> Option<&GenericByteViewArray<StringViewType>>

Downcast this to a StringViewArray returning None if not possible
§

fn as_string_view(&self) -> &GenericByteViewArray<StringViewType>

Downcast this to a StringViewArray panicking if not possible
§

fn as_binary_view_opt(&self) -> Option<&GenericByteViewArray<BinaryViewType>>

Downcast this to a BinaryViewArray returning None if not possible
§

fn as_binary_view(&self) -> &GenericByteViewArray<BinaryViewType>

Downcast this to a BinaryViewArray panicking if not possible
§

fn as_byte_view<T>(&self) -> &GenericByteViewArray<T>
where T: ByteViewType,

Downcast this to a GenericByteViewArray panicking if not possible
§

fn as_struct(&self) -> &StructArray

Downcast this to a StructArray panicking if not possible
§

fn as_union(&self) -> &UnionArray

Downcast this to a UnionArray panicking if not possible
§

fn as_list<O>(&self) -> &GenericListArray<O>
where O: OffsetSizeTrait,

Downcast this to a GenericListArray panicking if not possible
§

fn as_fixed_size_binary(&self) -> &FixedSizeBinaryArray

Downcast this to a FixedSizeBinaryArray panicking if not possible
§

fn as_fixed_size_list(&self) -> &FixedSizeListArray

Downcast this to a FixedSizeListArray panicking if not possible
§

fn as_map(&self) -> &MapArray

Downcast this to a MapArray panicking if not possible
§

fn as_dictionary<K>(&self) -> &DictionaryArray<K>

Downcast this to a DictionaryArray panicking if not possible
§

fn as_any_dictionary(&self) -> &dyn AnyDictionaryArray

Downcasts this to a AnyDictionaryArray panicking if not possible
§

impl Datum for &dyn Array

§

fn get(&self) -> (&dyn Array, bool)

Returns the value for this Datum and a boolean indicating if the value is scalar
§

impl Datum for dyn Array

§

fn get(&self) -> (&dyn Array, bool)

Returns the value for this Datum and a boolean indicating if the value is scalar
§

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

§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

impl PartialEq for dyn Array + '_

§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

Implementations on Foreign Types§

§

impl Array for Arc<dyn Array>

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

§

fn shrink_to_fit(&mut self)

For shared buffers, this is a no-op.

§

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

§

fn to_data(&self) -> ArrayData

§

fn into_data(self) -> ArrayData

§

fn data_type(&self) -> &DataType

§

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

§

fn len(&self) -> usize

§

fn is_empty(&self) -> bool

§

fn offset(&self) -> usize

§

fn nulls(&self) -> Option<&NullBuffer>

§

fn logical_nulls(&self) -> Option<NullBuffer>

§

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

§

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

§

fn null_count(&self) -> usize

§

fn logical_null_count(&self) -> usize

§

fn is_nullable(&self) -> bool

§

fn get_buffer_memory_size(&self) -> usize

§

fn get_array_memory_size(&self) -> usize

§

impl<T> Array for &T
where T: Array,

§

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

§

fn to_data(&self) -> ArrayData

§

fn into_data(self) -> ArrayData

§

fn data_type(&self) -> &DataType

§

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

§

fn len(&self) -> usize

§

fn is_empty(&self) -> bool

§

fn offset(&self) -> usize

§

fn nulls(&self) -> Option<&NullBuffer>

§

fn logical_nulls(&self) -> Option<NullBuffer>

§

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

§

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

§

fn null_count(&self) -> usize

§

fn logical_null_count(&self) -> usize

§

fn is_nullable(&self) -> bool

§

fn get_buffer_memory_size(&self) -> usize

§

fn get_array_memory_size(&self) -> usize

Implementors§

§

impl Array for BooleanArray

§

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<K, V> Array for TypedDictionaryArray<'_, K, V>

§

impl<OffsetSize> Array for GenericListArray<OffsetSize>
where OffsetSize: OffsetSizeTrait,

§

impl<OffsetSize> Array for GenericListViewArray<OffsetSize>
where OffsetSize: OffsetSizeTrait,

§

impl<R, V> Array for TypedRunArray<'_, R, V>
where R: RunEndIndexType, V: Sync,

§

impl<T> Array for DictionaryArray<T>

§

impl<T> Array for GenericByteArray<T>
where T: ByteArrayType,

§

impl<T> Array for GenericByteViewArray<T>
where T: ByteViewType + ?Sized,

§

impl<T> Array for PrimitiveArray<T>

§

impl<T> Array for RunArray<T>
where T: RunEndIndexType,