Struct arrow_array::builder::MapBuilder
source · pub struct MapBuilder<K: ArrayBuilder, V: ArrayBuilder> { /* private fields */ }
Expand description
Creates a new MapBuilder
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(), Int32Array::from(vec![1, 2, 4]));
assert_eq!(*array.keys(), StringArray::from(vec!["joe", "blogs", "foo"]));
Implementations§
source§impl<K: ArrayBuilder, V: ArrayBuilder> MapBuilder<K, V>
impl<K: ArrayBuilder, V: ArrayBuilder> MapBuilder<K, V>
sourcepub fn new(
field_names: Option<MapFieldNames>,
key_builder: K,
value_builder: V
) -> Self
pub fn new(
field_names: Option<MapFieldNames>,
key_builder: K,
value_builder: V
) -> Self
Creates a new MapBuilder
sourcepub fn with_capacity(
field_names: Option<MapFieldNames>,
key_builder: K,
value_builder: V,
capacity: usize
) -> Self
pub fn with_capacity(
field_names: Option<MapFieldNames>,
key_builder: K,
value_builder: V,
capacity: usize
) -> Self
Creates a new MapBuilder
with capacity
sourcepub fn append(&mut self, is_valid: bool) -> Result<(), ArrowError>
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.
sourcepub fn finish_cloned(&self) -> MapArray
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>
impl<K: ArrayBuilder, V: ArrayBuilder> ArrayBuilder for MapBuilder<K, V>
source§fn finish_cloned(&self) -> ArrayRef
fn finish_cloned(&self) -> ArrayRef
Builds the array without resetting the builder.
source§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Returns the builder as a mutable
Any
reference. Read more