pub struct MapArray {
data_type: DataType,
nulls: Option<NullBuffer>,
entries: StructArray,
value_offsets: OffsetBuffer<i32>,
}Expand description
An array of key-value maps
Keys should always be non-null, but values can be null.
MapArray is physically a ListArray of key values pairs stored as an entries
StructArray with 2 child fields.
§See also
MapBuilderfor how to construct aMapArraySelf::from_vec_of_mapsfor ergonomically creating maps for testing
Fields§
§data_type: DataType§nulls: Option<NullBuffer>§entries: StructArrayThe StructArray that is the direct child of this array
value_offsets: OffsetBuffer<i32>The start and end offsets of each entry
Implementations§
Source§impl MapArray
impl MapArray
Sourcepub fn try_new(
field: FieldRef,
offsets: OffsetBuffer<i32>,
entries: StructArray,
nulls: Option<NullBuffer>,
ordered: bool,
) -> Result<Self, ArrowError>
pub fn try_new( field: FieldRef, offsets: OffsetBuffer<i32>, entries: StructArray, nulls: Option<NullBuffer>, ordered: bool, ) -> Result<Self, ArrowError>
Create a new MapArray from the provided parts
See MapBuilder for a higher-level interface
to construct a MapArray
§Errors
Errors if
offsets.len() - 1 != nulls.len()offsets.last() > entries.len()field.is_nullable()entries.null_count() != 0entries.columns().len() != 2field.data_type() != entries.data_type()
Sourcepub fn new(
field: FieldRef,
offsets: OffsetBuffer<i32>,
entries: StructArray,
nulls: Option<NullBuffer>,
ordered: bool,
) -> Self
pub fn new( field: FieldRef, offsets: OffsetBuffer<i32>, entries: StructArray, nulls: Option<NullBuffer>, ordered: bool, ) -> Self
Create a new MapArray from the provided parts
See MapBuilder for a higher-level interface
to construct a MapArray
§Panics
Panics if Self::try_new returns an error
Sourcepub fn into_parts(
self,
) -> (FieldRef, OffsetBuffer<i32>, StructArray, Option<NullBuffer>, bool)
pub fn into_parts( self, ) -> (FieldRef, OffsetBuffer<i32>, StructArray, Option<NullBuffer>, bool)
Deconstruct this array into its constituent parts
Sourcepub fn offsets(&self) -> &OffsetBuffer<i32>
pub fn offsets(&self) -> &OffsetBuffer<i32>
Returns a reference to the offsets of this map
Unlike Self::value_offsets this returns the [OffsetBuffer]
allowing for zero-copy cloning
Sourcepub fn entries(&self) -> &StructArray
pub fn entries(&self) -> &StructArray
Returns a reference to the StructArray entries of this map
Sourcepub fn entries_fields(&self) -> (&Field, &Field)
pub fn entries_fields(&self) -> (&Field, &Field)
Returns a reference to the fields of the StructArray that backs this map.
Sourcepub fn value_type(&self) -> &DataType
pub fn value_type(&self) -> &DataType
Returns the data type of the map’s values.
Sourcepub unsafe fn value_unchecked(&self, i: usize) -> StructArray
pub unsafe fn value_unchecked(&self, i: usize) -> StructArray
Sourcepub fn value(&self, i: usize) -> StructArray
pub fn value(&self, i: usize) -> StructArray
Returns ith value of this map array.
This is a StructArray containing two fields
Note: This method does not check for nulls and the value is arbitrary
(but still well-defined) if is_null returns true for the index.
§Panics
Panics if index i is out of bounds
Sourcepub fn value_offsets(&self) -> &[i32]
pub fn value_offsets(&self) -> &[i32]
Returns the offset values in the offsets buffer
Sourcepub fn value_length(&self, i: usize) -> i32
pub fn value_length(&self, i: usize) -> i32
Returns the length for value at index i.
Sourcepub fn slice(&self, offset: usize, length: usize) -> Self
pub fn slice(&self, offset: usize, length: usize) -> Self
Returns a zero-copy slice of this array with the indicated offset and length.
Sourcepub fn iter(&self) -> MapArrayIter<'_>
pub fn iter(&self) -> MapArrayIter<'_>
constructs a new iterator
Source§impl MapArray
impl MapArray
fn try_new_from_array_data(data: ArrayData) -> Result<Self, ArrowError>
Sourcepub fn new_from_strings<'a>(
keys: impl Iterator<Item = &'a str>,
values: &dyn Array,
entry_offsets: &[u32],
) -> Result<Self, ArrowError>
pub fn new_from_strings<'a>( keys: impl Iterator<Item = &'a str>, values: &dyn Array, entry_offsets: &[u32], ) -> Result<Self, ArrowError>
Creates map array from provided keys, values and entry_offsets.
Sourcepub fn from_vec_of_maps<KeyArray, ValueArray, K, V>(
input: Vec<Option<Vec<(K, Option<V>)>>>,
ordered: bool,
) -> Self
pub fn from_vec_of_maps<KeyArray, ValueArray, K, V>( input: Vec<Option<Vec<(K, Option<V>)>>>, ordered: bool, ) -> Self
Helper to create MapArray from Vecs of entries so the code will look clean and straightforward
the input is: Vec<Option<Map>> where each Map is Vec<(Key, Option<Value>)>
Useful for tests, this should not be used for performance sensitive operations
use std::collections::HashMap;
let map = vec![
// {}
Some(vec![]),
// null
None,
// { "a": 1, "b": null, "cd": 4 }
Some(vec![
("a", Some(1)),
("b", None),
("cd", Some(4)),
]),
// { "e": 0 }
Some(vec![("e", Some(0))]),
];
let ordered = true;
// created map: [{}, null, {"a": 1, "b": null, "cd": 4}, {"e": 0}]
let map_array = MapArray::from_vec_of_maps::<StringArray, Int32Array, _, _>(map, ordered);
// Or you could fill the last 2 generics manually for the key array item and value array item
// let map_array = MapArray::from_vec_of_maps::<StringArray, Int32Array, &str, i32>(map, ordered);Trait Implementations§
Source§impl Array for MapArray
SAFETY: Correctly implements the contract of Arrow Arrays
impl Array for MapArray
SAFETY: Correctly implements the contract of Arrow Arrays
Source§fn data_type(&self) -> &DataType
fn data_type(&self) -> &DataType
DataType] of this array. Read moreSource§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 claim(&self, pool: &dyn MemoryPool)
fn claim(&self, pool: &dyn MemoryPool)
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 more