pub struct ListArray { /* private fields */ }Expand description
A column of variable-length lists over a shared child array.
Implementations§
Source§impl ListArray
impl ListArray
Sourcepub fn try_new(
field: Field,
offsets: ScalarBuffer<i32>,
values: ArrayRef,
validity: Option<Bitmap>,
) -> Result<Self>
pub fn try_new( field: Field, offsets: ScalarBuffer<i32>, values: ArrayRef, validity: Option<Bitmap>, ) -> Result<Self>
Builds a list array from its child, offsets and validity.
§Errors
- The offset errors listed on
validate_offsets. DataError::TypeMismatchwhen the child array’s type differs from the field’s.DataError::ValidityLengthMismatchwhen the bitmap length is wrong.
Sourcepub fn try_from_lengths(
field: Field,
lengths: impl IntoIterator<Item = usize>,
values: ArrayRef,
) -> Result<Self>
pub fn try_from_lengths( field: Field, lengths: impl IntoIterator<Item = usize>, values: ArrayRef, ) -> Result<Self>
Builds a list array from a child and per-list lengths.
The lengths must sum to the child’s length.
§Errors
DataError::TypeMismatchwhen the child’s type differs from the field’s.DataError::ChildLengthMismatchwhen the lengths do not add up.
use astrs_data::array::{Array, Int32Array, IntoArrayRef, ListArray};
use astrs_data::{DataType, Field};
let child = Int32Array::from_values([1, 2, 3]).into_array_ref();
let lists = ListArray::try_from_lengths(
Field::new("item", DataType::Int32, false),
[2, 1],
child,
)?;
assert_eq!(lists.len(), 2);Sourcepub fn new_null(field: Field, len: usize) -> Self
pub fn new_null(field: Field, len: usize) -> Self
An all-null list array of len slots over an empty child.
The child type comes from field; a field whose type cannot be
instantiated empty falls back to a Null child, which keeps the
constructor infallible.
Sourcepub fn value_offsets(&self) -> &[i32]
pub fn value_offsets(&self) -> &[i32]
The offset buffer, len + 1 entries.
Sourcepub const fn offsets_buffer(&self) -> &ScalarBuffer<i32>
pub const fn offsets_buffer(&self) -> &ScalarBuffer<i32>
The offset buffer as a shareable typed window.
See crate::array::GenericBinaryArray::offsets_buffer: the IPC
encoder clones this window rather than copying the offsets out of a
slice.
use astrs_data::array::{Int32Array, IntoArrayRef, ListArray};
use astrs_data::{DataType, Field};
let child = Int32Array::from_values([1, 2, 3]).into_array_ref();
let lists =
ListArray::try_from_lengths(Field::new("item", DataType::Int32, false), [2, 1], child)?;
assert_eq!(lists.offsets_buffer().as_slice(), &[0, 2, 3]);Sourcepub fn value(&self, index: usize) -> Option<ArrayRef>
pub fn value(&self, index: usize) -> Option<ArrayRef>
The list at index as a zero-copy slice of the child, ignoring
validity.
Returns None only when index is out of range.
Sourcepub fn get(&self, index: usize) -> Option<ArrayRef>
pub fn get(&self, index: usize) -> Option<ArrayRef>
The logical list at index: None when the slot is null or out of
range.
A null list and an empty list are different: the first returns
None, the second a zero-length array.
Sourcepub fn value_length(&self, index: usize) -> Option<usize>
pub fn value_length(&self, index: usize) -> Option<usize>
Number of child values in list index, ignoring validity.
Sourcepub fn slice(&self, offset: usize, len: usize) -> Self
pub fn slice(&self, offset: usize, len: usize) -> Self
A zero-copy sub-range, clamped to the array (the crate-wide slicing convention).
Only the offset buffer and validity are narrowed; the child array is
shared unchanged, exactly as for crate::array::GenericBinaryArray.
Sourcepub fn with_validity(&self, validity: Option<Bitmap>) -> Result<Self>
pub fn with_validity(&self, validity: Option<Bitmap>) -> Result<Self>
Returns a copy with a different validity bitmap.
§Errors
DataError::ValidityLengthMismatch when the bitmap length is wrong.
Trait Implementations§
Source§impl Array for ListArray
impl Array for ListArray
Source§fn as_any(&self) -> &dyn Any
fn as_any(&self) -> &dyn Any
ArrayExt::downcast.Source§fn validity(&self) -> Option<&Bitmap>
fn validity(&self) -> Option<&Bitmap>
None when every slot is valid. Read moreSource§fn buffer_memory_size(&self) -> usize
fn buffer_memory_size(&self) -> usize
Source§fn children(&self) -> Vec<&ArrayRef> ⓘ
fn children(&self) -> Vec<&ArrayRef> ⓘ
Source§fn null_count(&self) -> usize
fn null_count(&self) -> usize
Source§impl ArrayAccessor for &ListArray
impl ArrayAccessor for &ListArray
Source§impl<'a> IntoIterator for &'a ListArray
impl<'a> IntoIterator for &'a ListArray
Auto Trait Implementations§
impl !Freeze for ListArray
impl !RefUnwindSafe for ListArray
impl !UnwindSafe for ListArray
impl Send for ListArray
impl Sync for ListArray
impl Unpin for ListArray
impl UnsafeUnpin 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<A> IntoArrayRef for Awhere
A: Array,
impl<A> IntoArrayRef for Awhere
A: Array,
Source§fn into_array_ref(self) -> ArrayRef
fn into_array_ref(self) -> ArrayRef
self into a shared, dynamically typed column.