pub struct MapBuilder<K: ArrayBuilder, V: ArrayBuilder> {
offsets_builder: BufferBuilder<i32>,
null_buffer_builder: NullBufferBuilder,
field_names: MapFieldNames,
key_builder: K,
value_builder: V,
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: BufferBuilder<i32>
§null_buffer_builder: NullBufferBuilder
§field_names: MapFieldNames
§key_builder: K
§value_builder: V
§value_field: Option<FieldRef>
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 with_values_field(self, field: impl Into<FieldRef>) -> Self
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
Sourcepub fn entries(&mut self) -> (&mut K, &mut V)
pub fn entries(&mut self) -> (&mut K, &mut V)
Returns both the key and value array builders of the map
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.
fn finish_helper( &self, keys_arr: Arc<dyn Array>, values_arr: Arc<dyn Array>, offset_buffer: Buffer, nulls: Option<NullBuffer>, len: usize, ) -> MapArray
Sourcepub fn validity_slice(&self) -> Option<&[u8]>
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>
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 moreSource§impl<K: Debug + ArrayBuilder, V: Debug + ArrayBuilder> Debug for MapBuilder<K, V>
impl<K: Debug + ArrayBuilder, V: Debug + ArrayBuilder> Debug for MapBuilder<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for MapBuilder<K, V>
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>
impl<K, V> Unpin for MapBuilder<K, V>
impl<K, V> UnwindSafe for MapBuilder<K, V>where
K: UnwindSafe,
V: UnwindSafe,
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
Mutably borrows from an owned value. Read more