pub struct ListArray { /* private fields */ }
Expand description
A list array that stores variable-length lists of elements, similar to Vec<Vec<T>>
.
This mirrors the Apache Arrow List array encoding and provides efficient storage for nested data where each row contains a list of elements of the same type.
§Data Layout
The list array uses an offset-based encoding:
- Elements array: A flat array containing all list elements concatenated together
- Offsets array: Integer array where
offsets[i]
is an (inclusive) start index into the elements andoffsets[i+1]
is the (exclusive) stop index for thei
th list. - Validity: Optional mask indicating which lists are null
This allows for excellent cascading compression of the elements and offsets, as similar values are clustered together and the offsets have a predictable pattern and small deltas between consecutive elements.
§Offset Semantics
- Offsets must be non-nullable integers (i32, i64, etc.)
- Offsets array has length
n+1
wheren
is the number of lists - List
i
contains elements fromelements[offsets[i]..offsets[i+1]]
- Offsets must be monotonically increasing
§Examples
use vortex_array::arrays::{ListArray, PrimitiveArray};
use vortex_array::validity::Validity;
use vortex_array::IntoArray;
use std::sync::Arc;
// Create a list array representing [[1, 2], [3, 4, 5], []]
let elements = PrimitiveArray::from_iter([1i32, 2, 3, 4, 5]);
let offsets = PrimitiveArray::from_iter([0u32, 2, 5, 5]); // 3 lists
let list_array = ListArray::try_new(
elements.into_array(),
offsets.into_array(),
Validity::NonNullable,
).unwrap();
assert_eq!(list_array.len(), 3);
// Access individual lists
let first_list = list_array.elements_at(0).unwrap();
assert_eq!(first_list.len(), 2); // [1, 2]
let third_list = list_array.elements_at(2).unwrap();
assert!(third_list.is_empty()); // []
Implementations§
Source§impl ListArray
impl ListArray
pub fn try_new( elements: ArrayRef, offsets: ArrayRef, validity: Validity, ) -> VortexResult<Self>
Sourcepub fn offset_at(&self, index: usize) -> usize
pub fn offset_at(&self, index: usize) -> usize
Returns the offset at the given index from the list array.
Panics if the index is out of bounds.
Sourcepub fn elements_at(&self, index: usize) -> VortexResult<ArrayRef>
pub fn elements_at(&self, index: usize) -> VortexResult<ArrayRef>
Returns the elements at the given index from the list array.
Sourcepub fn sliced_elements(&self) -> VortexResult<ArrayRef>
pub fn sliced_elements(&self) -> VortexResult<ArrayRef>
Returns elements of the list array referenced by the offsets array
Sourcepub fn reset_offsets(&self) -> VortexResult<Self>
pub fn reset_offsets(&self) -> VortexResult<Self>
Create a copy of this array by adjusting offsets to start at 0 and removing elements not referenced by the offsets
Methods from Deref<Target = dyn Array>§
Sourcepub fn display_values(&self) -> impl Display
pub fn display_values(&self) -> impl Display
Display logical values of the array
For example, an i16
typed array containing the first five non-negative integers is displayed
as: [0i16, 1i16, 2i16, 3i16, 4i16]
.
§Examples
let array = buffer![0_i16, 1, 2, 3, 4].into_array();
assert_eq!(
format!("{}", array.display_values()),
"[0i16, 1i16, 2i16, 3i16, 4i16]",
)
See also: Array::display_as, DisplayArrayAs, and DisplayOptions.
Sourcepub fn display_as(&self, options: DisplayOptions) -> impl Display
pub fn display_as(&self, options: DisplayOptions) -> impl Display
Display the array as specified by the options.
See DisplayOptions for examples.
Sourcepub fn display_tree(&self) -> impl Display
pub fn display_tree(&self) -> impl Display
Display the tree of encodings of this array as an indented lists.
While some metadata (such as length, bytes and validity-rate) are included, the logical values of the array are not displayed. To view the logical values see Array::display_as and DisplayOptions.
§Examples
let array = buffer![0_i16, 1, 2, 3, 4].into_array();
let expected = "root: vortex.primitive(i16, len=5) nbytes=10 B (100.00%)
metadata: EmptyMetadata
buffer (align=2): 10 B (100.00%)
";
assert_eq!(format!("{}", array.display_tree()), expected);
Sourcepub fn as_opt<V: VTable>(&self) -> Option<&V::Array>
pub fn as_opt<V: VTable>(&self) -> Option<&V::Array>
Returns the array downcast to the given A
.
pub fn is_constant(&self) -> bool
pub fn is_constant_opts(&self, cost: Cost) -> bool
pub fn as_constant(&self) -> Option<Scalar>
Sourcepub fn nbytes(&self) -> u64
pub fn nbytes(&self) -> u64
Total size of the array in bytes, including all children and buffers.
Sourcepub fn to_array_iterator(&self) -> impl ArrayIterator + 'static
pub fn to_array_iterator(&self) -> impl ArrayIterator + 'static
Create an ArrayIterator
over the array.
Sourcepub fn serialize(
&self,
ctx: &ArrayContext,
options: &SerializeOptions,
) -> VortexResult<Vec<ByteBuffer>>
pub fn serialize( &self, ctx: &ArrayContext, options: &SerializeOptions, ) -> VortexResult<Vec<ByteBuffer>>
Serialize the array into a sequence of byte buffers that should be written contiguously. This function returns a vec to avoid copying data buffers.
Optionally, padding can be included to guarantee buffer alignment and ensure zero-copy reads within the context of an external file or stream. In this case, the alignment of the first byte buffer should be respected when writing the buffers to the stream or file.
The format of this blob is a sequence of data buffers, possible with prefixed padding,
followed by a flatbuffer containing an fba::Array
message, and ending with a
little-endian u32 describing the length of the flatbuffer message.
Sourcepub fn to_array_stream(&self) -> impl ArrayStream + 'static
pub fn to_array_stream(&self) -> impl ArrayStream + 'static
Create an ArrayStream
over the array.
Sourcepub fn as_null_typed(&self) -> NullTyped<'_>
pub fn as_null_typed(&self) -> NullTyped<'_>
Downcasts the array for null-specific behavior.
Sourcepub fn as_bool_typed(&self) -> BoolTyped<'_>
pub fn as_bool_typed(&self) -> BoolTyped<'_>
Downcasts the array for bool-specific behavior.
Sourcepub fn as_primitive_typed(&self) -> PrimitiveTyped<'_>
pub fn as_primitive_typed(&self) -> PrimitiveTyped<'_>
Downcasts the array for primitive-specific behavior.
Sourcepub fn as_decimal_typed(&self) -> DecimalTyped<'_>
pub fn as_decimal_typed(&self) -> DecimalTyped<'_>
Downcasts the array for decimal-specific behavior.
Sourcepub fn as_utf8_typed(&self) -> Utf8Typed<'_>
pub fn as_utf8_typed(&self) -> Utf8Typed<'_>
Downcasts the array for utf8-specific behavior.
Sourcepub fn as_binary_typed(&self) -> BinaryTyped<'_>
pub fn as_binary_typed(&self) -> BinaryTyped<'_>
Downcasts the array for binary-specific behavior.
Sourcepub fn as_struct_typed(&self) -> StructTyped<'_>
pub fn as_struct_typed(&self) -> StructTyped<'_>
Downcasts the array for struct-specific behavior.
Sourcepub fn as_list_typed(&self) -> ListTyped<'_>
pub fn as_list_typed(&self) -> ListTyped<'_>
Downcasts the array for list-specific behavior.
Sourcepub fn as_extension_typed(&self) -> ExtensionTyped<'_>
pub fn as_extension_typed(&self) -> ExtensionTyped<'_>
Downcasts the array for extension-specific behavior.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ListArray
impl !RefUnwindSafe for ListArray
impl Send for ListArray
impl Sync for ListArray
impl Unpin for ListArray
impl !UnwindSafe for ListArray
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more