Struct arrow::array::FixedSizeListArray
source · 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: Arc<Field>,
size: i32,
values: Arc<dyn Array>,
nulls: Option<NullBuffer>,
) -> FixedSizeListArray
pub fn new( field: Arc<Field>, size: i32, values: Arc<dyn Array>, nulls: Option<NullBuffer>, ) -> FixedSizeListArray
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: Arc<Field>,
size: i32,
values: Arc<dyn Array>,
nulls: Option<NullBuffer>,
) -> Result<FixedSizeListArray, ArrowError>
pub fn try_new( field: Arc<Field>, size: i32, values: Arc<dyn Array>, nulls: Option<NullBuffer>, ) -> Result<FixedSizeListArray, 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: Arc<Field>, size: i32, len: usize) -> FixedSizeListArray
pub fn new_null(field: Arc<Field>, size: i32, len: usize) -> FixedSizeListArray
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) -> (Arc<Field>, i32, Arc<dyn Array>, Option<NullBuffer>)
pub fn into_parts(self) -> (Arc<Field>, i32, Arc<dyn Array>, 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) -> FixedSizeListArray
pub fn slice(&self, offset: usize, len: usize) -> FixedSizeListArray
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) -> FixedSizeListArraywhere
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) -> FixedSizeListArraywhere
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) -> ArrayIter<&FixedSizeListArray> ⓘ
pub fn iter(&self) -> ArrayIter<&FixedSizeListArray> ⓘ
constructs a new iterator
Trait Implementations§
source§impl Array for FixedSizeListArray
impl Array for FixedSizeListArray
source§fn slice(&self, offset: usize, length: usize) -> Arc<dyn Array>
fn slice(&self, offset: usize, length: usize) -> Arc<dyn Array>
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§fn value(&self, index: usize) -> <&'a FixedSizeListArray as ArrayAccessor>::Item
fn value(&self, index: usize) -> <&'a FixedSizeListArray as ArrayAccessor>::Item
i
Read moresource§unsafe fn value_unchecked(
&self,
index: usize,
) -> <&'a FixedSizeListArray as ArrayAccessor>::Item
unsafe fn value_unchecked( &self, index: usize, ) -> <&'a FixedSizeListArray as ArrayAccessor>::Item
i
Read moresource§impl ArrayAccessor for FixedSizeListArray
impl ArrayAccessor for FixedSizeListArray
source§fn value(&self, index: usize) -> <FixedSizeListArray as ArrayAccessor>::Item
fn value(&self, index: usize) -> <FixedSizeListArray as ArrayAccessor>::Item
i
Read moresource§unsafe fn value_unchecked(
&self,
index: usize,
) -> <FixedSizeListArray as ArrayAccessor>::Item
unsafe fn value_unchecked( &self, index: usize, ) -> <FixedSizeListArray as ArrayAccessor>::Item
i
Read moresource§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§fn from(data: ArrayData) -> FixedSizeListArray
fn from(data: ArrayData) -> FixedSizeListArray
source§impl From<FixedSizeListArray> for ArrayData
impl From<FixedSizeListArray> for ArrayData
source§fn from(array: FixedSizeListArray) -> ArrayData
fn from(array: FixedSizeListArray) -> ArrayData
source§impl From<FixedSizeListArray> for FixedSizeBinaryArray
impl From<FixedSizeListArray> for FixedSizeBinaryArray
Creates a FixedSizeBinaryArray
from FixedSizeList<u8>
array
source§fn from(v: FixedSizeListArray) -> FixedSizeBinaryArray
fn from(v: FixedSizeListArray) -> FixedSizeBinaryArray
source§impl<OffsetSize> From<FixedSizeListArray> for GenericListArray<OffsetSize>where
OffsetSize: OffsetSizeTrait,
impl<OffsetSize> From<FixedSizeListArray> for GenericListArray<OffsetSize>where
OffsetSize: OffsetSizeTrait,
source§fn from(value: FixedSizeListArray) -> GenericListArray<OffsetSize>
fn from(value: FixedSizeListArray) -> GenericListArray<OffsetSize>
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)