pub struct FixedSizeListArray { /* private fields */ }
Expand description
An array of [fixed length lists], similar to JSON arrays
(e.g. ["A", "B"]
).
Lists are represented using a values
child
array where each list has a fixed size of value_length
.
Use FixedSizeListBuilder
to construct a FixedSizeListArray
.
§Representation
A FixedSizeListArray
can represent a list of values of any other
supported Arrow type. Each element of the FixedSizeListArray
itself is
a list which may contain NULL and non-null values,
or may itself be NULL.
For example, this FixedSizeListArray
stores lists of strings:
┌─────────────┐
│ [A,B] │
├─────────────┤
│ NULL │
├─────────────┤
│ [C,NULL] │
└─────────────┘
The values
of this FixedSizeListArray
s are stored in a child
StringArray
where logical null values take up values_length
slots in the array
as shown in the following diagram. The logical values
are shown on the left, and the actual FixedSizeListArray
encoding on the right
┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐
┌ ─ ─ ─ ─ ─ ─ ─ ─┐
┌─────────────┐ │ ┌───┐ ┌───┐ ┌──────┐ │
│ [A,B] │ │ 1 │ │ │ 1 │ │ A │ │ 0
├─────────────┤ │ ├───┤ ├───┤ ├──────┤ │
│ NULL │ │ 0 │ │ │ 1 │ │ B │ │ 1
├─────────────┤ │ ├───┤ ├───┤ ├──────┤ │
│ [C,NULL] │ │ 1 │ │ │ 0 │ │ ???? │ │ 2
└─────────────┘ │ └───┘ ├───┤ ├──────┤ │
| │ 0 │ │ ???? │ │ 3
Logical Values │ Validity ├───┤ ├──────┤ │
(nulls) │ │ 1 │ │ C │ │ 4
│ ├───┤ ├──────┤ │
│ │ 0 │ │ ???? │ │ 5
│ └───┘ └──────┘ │
│ Values │
│ FixedSizeListArray (Array) │
└ ─ ─ ─ ─ ─ ─ ─ ─┘
└ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘
§Example
// Construct a value array
let value_data = ArrayData::builder(DataType::Int32)
.len(9)
.add_buffer(Buffer::from_slice_ref(&[0, 1, 2, 3, 4, 5, 6, 7, 8]))
.build()
.unwrap();
let list_data_type = DataType::FixedSizeList(
Arc::new(Field::new("item", DataType::Int32, false)),
3,
);
let list_data = ArrayData::builder(list_data_type.clone())
.len(3)
.add_child_data(value_data.clone())
.build()
.unwrap();
let list_array = FixedSizeListArray::from(list_data);
let list0 = list_array.value(0);
let list1 = list_array.value(1);
let list2 = list_array.value(2);
assert_eq!( &[0, 1, 2], list0.as_any().downcast_ref::<Int32Array>().unwrap().values());
assert_eq!( &[3, 4, 5], list1.as_any().downcast_ref::<Int32Array>().unwrap().values());
assert_eq!( &[6, 7, 8], list2.as_any().downcast_ref::<Int32Array>().unwrap().values());
Implementations§
Source§impl FixedSizeListArray
impl FixedSizeListArray
Sourcepub fn new(
field: FieldRef,
size: i32,
values: ArrayRef,
nulls: Option<NullBuffer>,
) -> Self
pub fn new( field: FieldRef, size: i32, values: ArrayRef, nulls: Option<NullBuffer>, ) -> Self
Create a new FixedSizeListArray
with size
element size, panicking on failure
§Panics
Panics if Self::try_new
returns an error
Sourcepub fn try_new(
field: FieldRef,
size: i32,
values: ArrayRef,
nulls: Option<NullBuffer>,
) -> Result<Self, ArrowError>
pub fn try_new( field: FieldRef, size: i32, values: ArrayRef, nulls: Option<NullBuffer>, ) -> Result<Self, ArrowError>
Create a new FixedSizeListArray
from the provided parts, returning an error on failure
§Errors
size < 0
values.len() / size != nulls.len()
values.data_type() != field.data_type()
!field.is_nullable() && !nulls.expand(size).contains(values.logical_nulls())
Sourcepub fn new_null(field: FieldRef, size: i32, len: usize) -> Self
pub fn new_null(field: FieldRef, size: i32, len: usize) -> Self
Create a new FixedSizeListArray
of length len
where all values are null
§Panics
Panics if
size < 0
size * len
would overflowusize
Sourcepub fn into_parts(self) -> (FieldRef, i32, ArrayRef, Option<NullBuffer>)
pub fn into_parts(self) -> (FieldRef, i32, ArrayRef, Option<NullBuffer>)
Deconstruct this array into its constituent parts
Sourcepub fn value_type(&self) -> DataType
pub fn value_type(&self) -> DataType
Returns a clone of the value type of this list.
Sourcepub fn value_offset(&self, i: usize) -> i32
pub fn value_offset(&self, i: usize) -> i32
Returns the offset for value at index i
.
Note this doesn’t do any bound checking, for performance reason.
Sourcepub const fn value_length(&self) -> i32
pub const fn value_length(&self) -> i32
Returns the length for an element.
All elements have the same length as the array is a fixed size.
Sourcepub fn slice(&self, offset: usize, len: usize) -> Self
pub fn slice(&self, offset: usize, len: usize) -> Self
Returns a zero-copy slice of this array with the indicated offset and length.
Sourcepub fn from_iter_primitive<T, P, I>(iter: I, length: i32) -> Selfwhere
T: ArrowPrimitiveType,
P: IntoIterator<Item = Option<<T as ArrowPrimitiveType>::Native>>,
I: IntoIterator<Item = Option<P>>,
pub fn from_iter_primitive<T, P, I>(iter: I, length: i32) -> Selfwhere
T: ArrowPrimitiveType,
P: IntoIterator<Item = Option<<T as ArrowPrimitiveType>::Native>>,
I: IntoIterator<Item = Option<P>>,
Creates a FixedSizeListArray
from an iterator of primitive values
§Example
let data = vec![
Some(vec![Some(0), Some(1), Some(2)]),
None,
Some(vec![Some(3), None, Some(5)]),
Some(vec![Some(6), Some(7), Some(45)]),
];
let list_array = FixedSizeListArray::from_iter_primitive::<Int32Type, _, _>(data, 3);
println!("{:?}", list_array);
Sourcepub fn iter(&self) -> FixedSizeListIter<'_>
pub fn iter(&self) -> FixedSizeListIter<'_>
constructs a new iterator
Trait Implementations§
Source§impl Array for FixedSizeListArray
impl Array for FixedSizeListArray
Source§fn slice(&self, offset: usize, length: usize) -> ArrayRef
fn slice(&self, offset: usize, length: usize) -> ArrayRef
Source§fn offset(&self) -> usize
fn offset(&self) -> usize
0
. Read moreSource§fn nulls(&self) -> Option<&NullBuffer>
fn nulls(&self) -> Option<&NullBuffer>
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<'a> ArrayAccessor for &'a FixedSizeListArray
impl<'a> ArrayAccessor for &'a FixedSizeListArray
Source§impl ArrayAccessor for FixedSizeListArray
impl ArrayAccessor for FixedSizeListArray
Source§impl Clone for FixedSizeListArray
impl Clone for FixedSizeListArray
Source§fn clone(&self) -> FixedSizeListArray
fn clone(&self) -> FixedSizeListArray
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for FixedSizeListArray
impl Debug for FixedSizeListArray
Source§impl From<ArrayData> for FixedSizeListArray
impl From<ArrayData> for FixedSizeListArray
Source§impl From<FixedSizeListArray> for ArrayData
impl From<FixedSizeListArray> for ArrayData
Source§fn from(array: FixedSizeListArray) -> Self
fn from(array: FixedSizeListArray) -> Self
Source§impl From<FixedSizeListArray> for FixedSizeBinaryArray
impl From<FixedSizeListArray> for FixedSizeBinaryArray
Creates a FixedSizeBinaryArray
from FixedSizeList<u8>
array
Source§fn from(v: FixedSizeListArray) -> Self
fn from(v: FixedSizeListArray) -> Self
Source§impl<OffsetSize: OffsetSizeTrait> From<FixedSizeListArray> for GenericListArray<OffsetSize>
impl<OffsetSize: OffsetSizeTrait> From<FixedSizeListArray> for GenericListArray<OffsetSize>
Source§fn from(value: FixedSizeListArray) -> Self
fn from(value: FixedSizeListArray) -> Self
Source§impl PartialEq for FixedSizeListArray
impl PartialEq for FixedSizeListArray
Auto Trait Implementations§
impl Freeze for FixedSizeListArray
impl !RefUnwindSafe for FixedSizeListArray
impl Send for FixedSizeListArray
impl Sync for FixedSizeListArray
impl Unpin for FixedSizeListArray
impl !UnwindSafe for FixedSizeListArray
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)