pub struct MapBuilder<K: ArrayBuilder, V: ArrayBuilder> { /* private fields */ }
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"]));

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 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 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.

source

pub fn finish(&mut self) -> MapArray

Builds the MapArray

source

pub fn finish_cloned(&self) -> MapArray

Builds the MapArray without resetting the builder.

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 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> RefUnwindSafe for MapBuilder<K, V>where K: RefUnwindSafe, V: RefUnwindSafe,

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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.

source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
source§

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