Struct MapBuilder
pub struct MapBuilder<K, V>where
K: ArrayBuilder,
V: ArrayBuilder,{
offsets_builder: Vec<i32>,
null_buffer_builder: NullBufferBuilder,
field_names: MapFieldNames,
key_builder: K,
value_builder: V,
key_field: Option<Arc<Field>>,
value_field: Option<Arc<Field>>,
}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<Arc<Field>>§value_field: Option<Arc<Field>>Implementations§
§impl<K, V> MapBuilder<K, V>where
K: ArrayBuilder,
V: ArrayBuilder,
impl<K, V> MapBuilder<K, V>where
K: ArrayBuilder,
V: ArrayBuilder,
pub fn new(
field_names: Option<MapFieldNames>,
key_builder: K,
value_builder: V,
) -> MapBuilder<K, V>
pub fn new( field_names: Option<MapFieldNames>, key_builder: K, value_builder: V, ) -> MapBuilder<K, V>
Creates a new MapBuilder
pub fn with_capacity(
field_names: Option<MapFieldNames>,
key_builder: K,
value_builder: V,
capacity: usize,
) -> MapBuilder<K, V>
pub fn with_capacity( field_names: Option<MapFieldNames>, key_builder: K, value_builder: V, capacity: usize, ) -> MapBuilder<K, V>
Creates a new MapBuilder with capacity
pub fn with_keys_field(self, field: impl Into<Arc<Field>>) -> MapBuilder<K, V>
pub fn with_keys_field(self, field: impl Into<Arc<Field>>) -> MapBuilder<K, V>
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
pub fn with_values_field(self, field: impl Into<Arc<Field>>) -> MapBuilder<K, V>
pub fn with_values_field(self, field: impl Into<Arc<Field>>) -> MapBuilder<K, V>
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
pub 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
pub 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,
the next offset would be less than the last offset, or the number of entries
exceeds i32::MAX. A rejected append leaves the builder unchanged.
pub fn append_nulls(&mut self, n: usize) -> Result<(), ArrowError>
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,
the next offset would be less than the last offset, or the number of entries
exceeds i32::MAX. A rejected append leaves the builder unchanged.
pub fn finish(&mut self) -> MapArray
pub fn finish(&mut self) -> MapArray
Builds the MapArray
§Panics
Panics if:
- the fields set with
Self::with_keys_fieldorSelf::with_values_fielddo not match the data types of the key and value builders - the keys contain nulls
- the key or value builder was finished after the last append
pub fn finish_cloned(&self) -> MapArray
pub fn finish_cloned(&self) -> MapArray
Builds the MapArray without resetting the builder.
§Panics
Panics if:
- the fields set with
Self::with_keys_fieldorSelf::with_values_fielddo not match the data types of the key and value builders - the keys contain nulls
- the key or value builder was finished after the last append
pub fn validity_slice(&self) -> Option<&[u8]>
pub fn validity_slice(&self) -> Option<&[u8]>
Returns the current null buffer as a slice
Trait Implementations§
§impl<K, V> ArrayBuilder for MapBuilder<K, V>where
K: ArrayBuilder,
V: ArrayBuilder,
impl<K, V> ArrayBuilder for MapBuilder<K, V>where
K: ArrayBuilder,
V: ArrayBuilder,
§fn finish_cloned(&self) -> Arc<dyn Array> ⓘ
fn finish_cloned(&self) -> Arc<dyn Array> ⓘ
Builds the array without resetting the builder.
§fn finish_preserve_values(&mut self) -> Arc<dyn Array> ⓘ
fn finish_preserve_values(&mut self) -> Arc<dyn Array> ⓘ
§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Any reference. Read more§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Any reference. Read more§fn into_box_any(self: Box<MapBuilder<K, V>>) -> Box<dyn Any>
fn into_box_any(self: Box<MapBuilder<K, V>>) -> Box<dyn Any>
Any.