Struct arrow2::array::BinaryArray

source ·
pub struct BinaryArray<O: Offset> { /* private fields */ }
Expand description

A BinaryArray is Arrow’s semantically equivalent of an immutable Vec<Option<Vec<u8>>>. It implements Array.

The size of this struct is O(1), as all data is stored behind an std::sync::Arc.

Example

use arrow2::array::BinaryArray;
use arrow2::bitmap::Bitmap;
use arrow2::buffer::Buffer;

let array = BinaryArray::<i32>::from([Some([1, 2].as_ref()), None, Some([3].as_ref())]);
assert_eq!(array.value(0), &[1, 2]);
assert_eq!(array.iter().collect::<Vec<_>>(), vec![Some([1, 2].as_ref()), None, Some([3].as_ref())]);
assert_eq!(array.values_iter().collect::<Vec<_>>(), vec![[1, 2].as_ref(), &[], &[3]]);
// the underlying representation:
assert_eq!(array.values(), &Buffer::from(vec![1, 2, 3]));
assert_eq!(array.offsets().buffer(), &Buffer::from(vec![0, 2, 2, 3]));
assert_eq!(array.validity(), Some(&Bitmap::from([true, false, true])));

Generic parameter

The generic parameter Offset can only be i32 or i64 and tradeoffs maximum array length with memory usage:

  • the sum of lengths of all elements cannot exceed Offset::MAX
  • the total size of the underlying data is array.len() * size_of::<Offset>() + sum of lengths of all elements

Safety

The following invariants hold:

  • Two consecutives offsets casted (as) to usize are valid slices of values.
  • len is equal to validity.len(), when defined.

Implementations§

Returns a BinaryArray created from its internal representation.

Errors

This function returns an error iff:

  • The last offset is not equal to the values’ length.
  • the validity’s length is not equal to offsets.len().
  • The data_type’s crate::datatypes::PhysicalType is not equal to either Binary or LargeBinary.
Implementation

This function is O(1)

Creates a new BinaryArray from slices of &[u8].

Creates a new BinaryArray from a slice of optional &[u8].

Returns an iterator of Option<&[u8]> over every element of this array.

Returns an iterator of &[u8] over every element of this array, ignoring the validity

Returns the length of this array

Returns the element at index i

Panics

iff i >= self.len()

Returns the element at index i

Safety

Assumes that the i < self.len.

Returns the DataType of this array.

Returns the values of this BinaryArray.

Returns the offsets of this BinaryArray.

The optional validity.

Creates a new BinaryArray by slicing this BinaryArray.

Implementation

This function is O(1): all data will be shared between both arrays.

Panics

iff offset + length > self.len().

Creates a new BinaryArray by slicing this BinaryArray.

Implementation

This function is O(1): all data will be shared between both arrays.

Safety

The caller must ensure that offset + length <= self.len().

Boxes self into a Box<dyn Array>.

Boxes self into a std::sync::Arc<dyn Array>.

Returns this BinaryArray with a new validity.

Panic

Panics iff validity.len() != self.len().

Sets the validity of this BinaryArray.

Panics

This function panics iff values.len() != self.len().

Try to convert this BinaryArray to a MutableBinaryArray

Creates an empty BinaryArray, i.e. whose .len is zero.

Creates an null BinaryArray, i.e. whose .null_count() == .len().

Returns the default DataType, DataType::Binary or DataType::LargeBinary

Alias for unwrapping Self::try_new

Returns a BinaryArray from an iterator of trusted length.

The BinaryArray is guaranteed to not have a validity

Returns a new BinaryArray from a Iterator of &[u8].

The BinaryArray is guaranteed to not have a validity

Creates a BinaryArray from an iterator of trusted length.

Safety

The iterator must be TrustedLen. I.e. that size_hint().1 correctly reports its length.

Creates a BinaryArray from a TrustedLen

Creates a BinaryArray from an falible iterator of trusted length.

Safety

The iterator must be TrustedLen. I.e. that size_hint().1 correctly reports its length.

Creates a BinaryArray from an fallible iterator of trusted length.

Trait Implementations§

Converts itself to a reference of Any, which enables downcasting to concrete types.
Converts itself to a mutable reference of Any, which enables mutable downcasting to concrete types.
The length of the Array. Every array has a length corresponding to the number of elements (slots).
The DataType of the Array. In combination with Array::as_any, this can be used to downcast trait objects (dyn Array) to concrete arrays.
The validity of the Array: every array has an optional Bitmap that, when available specifies whether the array slot is valid or not (null). When the validity is None, all slots are valid.
Slices the Array, returning a new Box<dyn Array>. Read more
Slices the Array, returning a new Box<dyn Array>. Read more
Clones this Array with a new new assigned bitmap. Read more
Clone a &dyn Array to an owned Box<dyn Array>.
whether the array is empty
The number of null slots on this Array. Read more
Returns whether slot i is null. Read more
Returns whether slot i is valid. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Creates a value from an iterator. Read more
The values of the array
The offsets of the array
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.