Skip to main content

MapBuilder

Struct MapBuilder 

Source
pub struct MapBuilder<K: ArrayBuilder, V: ArrayBuilder> {
    offsets_builder: Vec<i32>,
    null_buffer_builder: NullBufferBuilder,
    field_names: MapFieldNames,
    key_builder: K,
    value_builder: V,
    key_field: Option<FieldRef>,
    value_field: Option<FieldRef>,
}
Expand description

Builder for MapArray


let string_builder = StringBuilder::new();
let int_builder = Int32Builder::with_capacity(4);

// Construct `[{"joe": 1}, {"blogs": 2, "foo": 4}, {}, null]`
let mut builder = MapBuilder::new(None, string_builder, int_builder);

builder.keys().append_value("joe");
builder.values().append_value(1);
builder.append(true).unwrap();

builder.keys().append_value("blogs");
builder.values().append_value(2);
builder.keys().append_value("foo");
builder.values().append_value(4);
builder.append(true).unwrap();
builder.append(true).unwrap();
builder.append(false).unwrap();

let array = builder.finish();
assert_eq!(array.value_offsets(), &[0, 1, 3, 3, 3]);
assert_eq!(array.values().as_ref(), &Int32Array::from(vec![1, 2, 4]));
assert_eq!(array.keys().as_ref(), &StringArray::from(vec!["joe", "blogs", "foo"]));

Fields§

§offsets_builder: Vec<i32>§null_buffer_builder: NullBufferBuilder§field_names: MapFieldNames§key_builder: K§value_builder: V§key_field: Option<FieldRef>§value_field: Option<FieldRef>

Implementations§

Source§

impl<K: ArrayBuilder, V: ArrayBuilder> MapBuilder<K, V>

Source

pub fn new( field_names: Option<MapFieldNames>, key_builder: K, value_builder: V, ) -> Self

Creates a new MapBuilder

Source

pub fn with_capacity( field_names: Option<MapFieldNames>, key_builder: K, value_builder: V, capacity: usize, ) -> Self

Creates a new MapBuilder with capacity

Source

pub fn with_keys_field(self, field: impl Into<FieldRef>) -> Self

Override the field passed to MapBuilder::new

By default, a non-nullable field is created with the name keys

Note: Self::finish and Self::finish_cloned will panic if the field’s data type does not match that of K or the field is nullable

Source

pub fn with_values_field(self, field: impl Into<FieldRef>) -> Self

Override the field passed to MapBuilder::new

By default, a nullable field is created with the name values

Note: Self::finish and Self::finish_cloned will panic if the field’s data type does not match that of V

Source

pub fn keys(&mut self) -> &mut K

Returns the key array builder of the map

Source

pub fn values(&mut self) -> &mut V

Returns the value array builder of the map

Source

pub fn entries(&mut self) -> (&mut K, &mut V)

Returns both the key and value array builders of the map

Source

fn validate_equal_lengths(&self) -> Result<(), ArrowError>

Validates that key and value builders have equal lengths.

Source

fn next_offset(&self) -> Result<i32, ArrowError>

Returns the offset of the next map slot, i.e. the current number of entries.

Returns an error if the number of entries does not fit in an i32 offset.

Source

pub fn append(&mut self, is_valid: bool) -> Result<(), ArrowError>

Finish the current map array slot

Returns an error if the key and values builders are in an inconsistent state, or if the number of entries exceeds i32::MAX.

Source

pub fn append_nulls(&mut self, n: usize) -> Result<(), ArrowError>

Append n nulls to this MapBuilder

Returns an error if the key and values builders are in an inconsistent state, or if the number of entries exceeds i32::MAX.

Source

pub fn finish(&mut self) -> MapArray

Builds the MapArray

§Panics

Panics if the fields set with Self::with_keys_field or Self::with_values_field do not match the data types of the key and value builders, or if the keys contain nulls

Source

pub fn finish_cloned(&self) -> MapArray

Builds the MapArray without resetting the builder.

§Panics

Panics if the fields set with Self::with_keys_field or Self::with_values_field do not match the data types of the key and value builders, or if the keys contain nulls

Source

fn finish_preserve_values(&mut self) -> MapArray

Source

fn finish_helper( &self, keys_arr: Arc<dyn Array>, values_arr: Arc<dyn Array>, offset_buffer: Buffer, nulls: Option<NullBuffer>, len: usize, ) -> MapArray

Source

pub fn validity_slice(&self) -> Option<&[u8]>

Returns the current null buffer as a slice

Trait Implementations§

Source§

impl<K: ArrayBuilder, V: ArrayBuilder> ArrayBuilder for MapBuilder<K, V>

Source§

fn finish_cloned(&self) -> ArrayRef

Builds the array without resetting the builder.

Source§

fn len(&self) -> usize

Returns the number of array slots in the builder
Source§

fn finish(&mut self) -> ArrayRef

Builds the array
Source§

fn finish_preserve_values(&mut self) -> ArrayRef

Builds the array without resetting the values builder. Read more
Source§

fn as_any(&self) -> &dyn Any

Returns the builder as a non-mutable Any reference. Read more
Source§

fn as_any_mut(&mut self) -> &mut dyn Any

Returns the builder as a mutable Any reference. Read more
Source§

fn into_box_any(self: Box<Self>) -> Box<dyn Any>

Returns the boxed builder as a box of Any.
Source§

fn is_empty(&self) -> bool

Returns whether number of array slots is zero
Source§

impl<K: Debug + ArrayBuilder, V: Debug + ArrayBuilder> Debug for MapBuilder<K, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, V> !Freeze for MapBuilder<K, V>

§

impl<K, V> Forget for MapBuilder<K, V>

§

impl<K, V> Move for MapBuilder<K, V>

§

impl<K, V> RefUnwindSafe for MapBuilder<K, V>

§

impl<K, V> Send for MapBuilder<K, V>

§

impl<K, V> Sync for MapBuilder<K, V>

§

impl<K, V> Unpin for MapBuilder<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnsafeUnpin for MapBuilder<K, V>
where K: UnsafeUnpin, V: UnsafeUnpin,

§

impl<K, V> UnwindSafe for MapBuilder<K, V>
where K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.