pub struct GenericListViewArray<OffsetSize: OffsetSizeTrait> { /* private fields */ }
Expand description
An array of variable length lists, specifically in the list-view layout.
Differs from GenericListArray
(which represents the list layout) in that
the sizes of the child arrays are explicitly encoded in a separate buffer, instead
of being derived from the difference between subsequent offsets in the offset buffer.
This allows the offsets (and subsequently child data) to be out of order. It also allows take / filter operations to be implemented without copying the underlying data.
§Representation
Given the same example array from GenericListArray
, it would be represented
as such via a list-view layout array:
┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
┌ ─ ─ ─ ─ ─ ─ ┐ │
┌─────────────┐ ┌───────┐ │ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐
│ [A,B,C] │ │ (0,3) │ │ 1 │ │ 0 │ │ 3 │ │ │ 1 │ │ A │ │ 0 │
├─────────────┤ ├───────┤ │ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤
│ [] │ │ (3,0) │ │ 1 │ │ 3 │ │ 0 │ │ │ 1 │ │ B │ │ 1 │
├─────────────┤ ├───────┤ │ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤
│ NULL │ │ (?,?) │ │ 0 │ │ ? │ │ ? │ │ │ 1 │ │ C │ │ 2 │
├─────────────┤ ├───────┤ │ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤
│ [D] │ │ (4,1) │ │ 1 │ │ 4 │ │ 1 │ │ │ ? │ │ ? │ │ 3 │
├─────────────┤ ├───────┤ │ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤
│ [NULL, F] │ │ (5,2) │ │ 1 │ │ 5 │ │ 2 │ │ │ 1 │ │ D │ │ 4 │
└─────────────┘ └───────┘ │ └───┘ └───┘ └───┘ ├───┤ ├───┤
│ │ 0 │ │ ? │ │ 5 │
Logical Logical │ Validity Offsets Sizes ├───┤ ├───┤
Values Offset (nulls) │ │ 1 │ │ F │ │ 6 │
& Size │ └───┘ └───┘
│ Values │ │
(offsets[i], │ ListViewArray (Array)
sizes[i]) └ ─ ─ ─ ─ ─ ─ ┘ │
└ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
Another way of representing the same array but taking advantage of the offsets being out of order:
┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
┌ ─ ─ ─ ─ ─ ─ ┐ │
┌─────────────┐ ┌───────┐ │ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐
│ [A,B,C] │ │ (2,3) │ │ 1 │ │ 2 │ │ 3 │ │ │ 0 │ │ ? │ │ 0 │
├─────────────┤ ├───────┤ │ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤
│ [] │ │ (0,0) │ │ 1 │ │ 0 │ │ 0 │ │ │ 1 │ │ F │ │ 1 │
├─────────────┤ ├───────┤ │ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤
│ NULL │ │ (?,?) │ │ 0 │ │ ? │ │ ? │ │ │ 1 │ │ A │ │ 2 │
├─────────────┤ ├───────┤ │ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤
│ [D] │ │ (5,1) │ │ 1 │ │ 5 │ │ 1 │ │ │ 1 │ │ B │ │ 3 │
├─────────────┤ ├───────┤ │ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤
│ [NULL, F] │ │ (0,2) │ │ 1 │ │ 0 │ │ 2 │ │ │ 1 │ │ C │ │ 4 │
└─────────────┘ └───────┘ │ └───┘ └───┘ └───┘ ├───┤ ├───┤
│ │ 1 │ │ D │ │ 5 │
Logical Logical │ Validity Offsets Sizes └───┘ └───┘
Values Offset (nulls) │ Values │ │
& Size │ (Array)
└ ─ ─ ─ ─ ─ ─ ┘ │
(offsets[i], │ ListViewArray
sizes[i]) │
└ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
Implementations§
Source§impl<OffsetSize: OffsetSizeTrait> GenericListViewArray<OffsetSize>
impl<OffsetSize: OffsetSizeTrait> GenericListViewArray<OffsetSize>
Sourcepub const DATA_TYPE_CONSTRUCTOR: fn(_: FieldRef) -> DataType
pub const DATA_TYPE_CONSTRUCTOR: fn(_: FieldRef) -> DataType
The data type constructor of listview array.
The input is the schema of the child array and
the output is the DataType
, ListView or LargeListView.
Sourcepub fn try_new(
field: FieldRef,
offsets: ScalarBuffer<OffsetSize>,
sizes: ScalarBuffer<OffsetSize>,
values: ArrayRef,
nulls: Option<NullBuffer>,
) -> Result<Self, ArrowError>
pub fn try_new( field: FieldRef, offsets: ScalarBuffer<OffsetSize>, sizes: ScalarBuffer<OffsetSize>, values: ArrayRef, nulls: Option<NullBuffer>, ) -> Result<Self, ArrowError>
Create a new GenericListViewArray
from the provided parts
§Errors
Errors if
offsets.len() != sizes.len()
offsets.len() != nulls.len()
offsets[i] > values.len()
!field.is_nullable() && values.is_nullable()
field.data_type() != values.data_type()
0 <= offsets[i] <= length of the child array
0 <= offsets[i] + size[i] <= length of the child array
Sourcepub fn new(
field: FieldRef,
offsets: ScalarBuffer<OffsetSize>,
sizes: ScalarBuffer<OffsetSize>,
values: ArrayRef,
nulls: Option<NullBuffer>,
) -> Self
pub fn new( field: FieldRef, offsets: ScalarBuffer<OffsetSize>, sizes: ScalarBuffer<OffsetSize>, values: ArrayRef, nulls: Option<NullBuffer>, ) -> Self
Create a new GenericListViewArray
from the provided parts
§Panics
Panics if Self::try_new
returns an error
Sourcepub fn new_null(field: FieldRef, len: usize) -> Self
pub fn new_null(field: FieldRef, len: usize) -> Self
Create a new GenericListViewArray
of length len
where all values are null
Sourcepub fn into_parts(
self,
) -> (FieldRef, ScalarBuffer<OffsetSize>, ScalarBuffer<OffsetSize>, ArrayRef, Option<NullBuffer>)
pub fn into_parts( self, ) -> (FieldRef, ScalarBuffer<OffsetSize>, ScalarBuffer<OffsetSize>, ArrayRef, Option<NullBuffer>)
Deconstruct this array into its constituent parts
Sourcepub fn offsets(&self) -> &ScalarBuffer<OffsetSize>
pub fn offsets(&self) -> &ScalarBuffer<OffsetSize>
Returns a reference to the offsets of this list
Unlike Self::value_offsets
this returns the ScalarBuffer
allowing for zero-copy cloning
Sourcepub fn sizes(&self) -> &ScalarBuffer<OffsetSize>
pub fn sizes(&self) -> &ScalarBuffer<OffsetSize>
Returns a reference to the sizes of this list
Unlike Self::value_sizes
this returns the ScalarBuffer
allowing for zero-copy cloning
Sourcepub fn value_type(&self) -> DataType
pub fn value_type(&self) -> DataType
Returns a clone of the value type of this list.
Sourcepub unsafe fn value_unchecked(&self, i: usize) -> ArrayRef
pub unsafe fn value_unchecked(&self, i: usize) -> ArrayRef
Returns ith value of this list view array.
§Safety
Caller must ensure that the index is within the array bounds
Sourcepub fn value_offsets(&self) -> &[OffsetSize]
pub fn value_offsets(&self) -> &[OffsetSize]
Returns the offset values in the offsets buffer
Sourcepub fn value_sizes(&self) -> &[OffsetSize]
pub fn value_sizes(&self) -> &[OffsetSize]
Returns the sizes values in the offsets buffer
Sourcepub fn value_size(&self, i: usize) -> OffsetSize
pub fn value_size(&self, i: usize) -> OffsetSize
Returns the size for value at index i
.
Sourcepub fn value_offset(&self, i: usize) -> OffsetSize
pub fn value_offset(&self, i: usize) -> OffsetSize
Returns the offset for value at index i
.
Sourcepub fn iter(&self) -> GenericListViewArrayIter<'_, OffsetSize>
pub fn iter(&self) -> GenericListViewArrayIter<'_, OffsetSize>
Constructs a new iterator
Trait Implementations§
Source§impl<OffsetSize: OffsetSizeTrait> Array for GenericListViewArray<OffsetSize>
impl<OffsetSize: OffsetSizeTrait> Array for GenericListViewArray<OffsetSize>
Source§fn slice(&self, offset: usize, length: usize) -> ArrayRef
fn slice(&self, offset: usize, length: usize) -> ArrayRef
Source§fn shrink_to_fit(&mut self)
fn shrink_to_fit(&mut self)
Source§fn offset(&self) -> usize
fn offset(&self) -> usize
0
. Read moreSource§fn nulls(&self) -> Option<&NullBuffer>
fn nulls(&self) -> Option<&NullBuffer>
Source§fn logical_null_count(&self) -> usize
fn logical_null_count(&self) -> usize
Source§fn get_buffer_memory_size(&self) -> usize
fn get_buffer_memory_size(&self) -> usize
Source§fn get_array_memory_size(&self) -> usize
fn get_array_memory_size(&self) -> usize
get_buffer_memory_size()
and
includes the overhead of the data structures that contain the pointers to the various buffers.Source§fn logical_nulls(&self) -> Option<NullBuffer>
fn logical_nulls(&self) -> Option<NullBuffer>
NullBuffer
that represents the logical
null values of this array, if any. Read moreSource§fn null_count(&self) -> usize
fn null_count(&self) -> usize
Source§fn is_nullable(&self) -> bool
fn is_nullable(&self) -> bool
false
if the array is guaranteed to not contain any logical nulls Read moreSource§impl<OffsetSize: OffsetSizeTrait> ArrayAccessor for &GenericListViewArray<OffsetSize>
impl<OffsetSize: OffsetSizeTrait> ArrayAccessor for &GenericListViewArray<OffsetSize>
Source§impl<OffsetSize: Clone + OffsetSizeTrait> Clone for GenericListViewArray<OffsetSize>
impl<OffsetSize: Clone + OffsetSizeTrait> Clone for GenericListViewArray<OffsetSize>
Source§fn clone(&self) -> GenericListViewArray<OffsetSize>
fn clone(&self) -> GenericListViewArray<OffsetSize>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more