pub struct VariantArrayBuilder {
    nulls: NullBufferBuilder,
    metadata_builder: WritableMetadataBuilder,
    metadata_offsets: Vec<usize>,
    value_builder: ValueBuilder,
    value_offsets: Vec<usize>,
    fields: Fields,
}Expand description
A builder for VariantArray
This builder is used to construct a VariantArray and allows APIs for
adding metadata
This builder always creates a VariantArray using [BinaryViewArray] for both
the metadata and value fields.
§TODO
- Support shredding: https://github.com/apache/arrow-rs/issues/7895
§Example:
// Create a new VariantArrayBuilder with a capacity of 100 rows
let mut builder = VariantArrayBuilder::new(100);
// append variant values
builder.append_variant(Variant::from(42));
// append a null row (note not a Variant::Null)
builder.append_null();
// append an object to the builder using VariantBuilderExt methods directly
builder.new_object()
  .with_field("foo", "bar")
  .finish();
// bulk insert a list of values
// `Option::None` is a null value
builder.extend([None, Some(Variant::from("norm"))]);
// create the final VariantArray
let variant_array = builder.build();
assert_eq!(variant_array.len(), 5);
// // Access the values
// row 1 is not null and is an integer
assert!(!variant_array.is_null(0));
assert_eq!(variant_array.value(0), Variant::from(42i32));
// row 1 is null
assert!(variant_array.is_null(1));
// row 2 is not null and is an object
assert!(!variant_array.is_null(2));
let value = variant_array.value(2);
let obj = value.as_object().expect("expected object");
assert_eq!(obj.get("foo"), Some(Variant::from("bar")));
// row 3 is null
assert!(variant_array.is_null(3));
// row 4 is not null and is a short string
assert!(!variant_array.is_null(4));
let value = variant_array.value(4);
assert_eq!(value, Variant::ShortString(ShortString::try_new("norm").unwrap()));Fields§
§nulls: NullBufferBuilderNulls
metadata_builder: WritableMetadataBuilderbuilder for all the metadata
metadata_offsets: Vec<usize>ending offset for each serialized metadata dictionary in the buffer
value_builder: ValueBuilderbuilder for values
value_offsets: Vec<usize>ending offset for each serialized variant value in the buffer
fields: FieldsThe fields of the final StructArray
TODO: 1) Add extension type metadata TODO: 2) Add support for shredding
Implementations§
Source§impl VariantArrayBuilder
 
impl VariantArrayBuilder
pub fn new(row_capacity: usize) -> Self
Sourcepub fn build(self) -> VariantArray
 
pub fn build(self) -> VariantArray
Build the final builder
Sourcepub fn append_null(&mut self)
 
pub fn append_null(&mut self)
Appends a null row to the builder.
Sourcepub fn append_variant(&mut self, variant: Variant<'_, '_>)
 
pub fn append_variant(&mut self, variant: Variant<'_, '_>)
Append the [Variant] to the builder as the next row
Sourcefn parent_state(&mut self) -> ParentState<'_, ArrayBuilderState<'_>>
 
fn parent_state(&mut self) -> ParentState<'_, ArrayBuilderState<'_>>
Creates a builder-specific parent state
Trait Implementations§
Source§impl Debug for VariantArrayBuilder
 
impl Debug for VariantArrayBuilder
Source§impl<'m, 'v> Extend<Option<Variant<'m, 'v>>> for VariantArrayBuilder
 
impl<'m, 'v> Extend<Option<Variant<'m, 'v>>> for VariantArrayBuilder
Source§fn extend<T: IntoIterator<Item = Option<Variant<'m, 'v>>>>(&mut self, iter: T)
 
fn extend<T: IntoIterator<Item = Option<Variant<'m, 'v>>>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
 
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
 
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl VariantBuilderExt for VariantArrayBuilder
 
impl VariantBuilderExt for VariantArrayBuilder
Source§fn append_null(&mut self)
 
fn append_null(&mut self)
Appending NULL to a variant array produces an actual NULL value
Source§type State<'a> = ArrayBuilderState<'a>
where
    Self: 'a
 
type State<'a> = ArrayBuilderState<'a> where Self: 'a
The builder specific state used by nested builders
Source§fn append_value<'m, 'v>(&mut self, value: impl Into<Variant<'m, 'v>>)
 
fn append_value<'m, 'v>(&mut self, value: impl Into<Variant<'m, 'v>>)
Appends a new variant value to this builder. See e.g. [
VariantBuilder::append_value].Source§fn try_new_list(
    &mut self,
) -> Result<ListBuilder<'_, Self::State<'_>>, ArrowError>
 
fn try_new_list( &mut self, ) -> Result<ListBuilder<'_, Self::State<'_>>, ArrowError>
Creates a nested list builder. See e.g. [
VariantBuilder::new_list]. Returns an error if
the nested builder cannot be created, see e.g. [ObjectBuilder::try_new_list].Source§fn try_new_object(
    &mut self,
) -> Result<ObjectBuilder<'_, Self::State<'_>>, ArrowError>
 
fn try_new_object( &mut self, ) -> Result<ObjectBuilder<'_, Self::State<'_>>, ArrowError>
Creates a nested object builder. See e.g. [
VariantBuilder::new_object]. Returns an error
if the nested builder cannot be created, see e.g. [ObjectBuilder::try_new_object].§fn new_list(&mut self) -> ListBuilder<'_, Self::State<'_>>
 
fn new_list(&mut self) -> ListBuilder<'_, Self::State<'_>>
Creates a nested list builder. See e.g. [
VariantBuilder::new_list]. Panics if the nested
builder cannot be created, see e.g. [ObjectBuilder::new_list].§fn new_object(&mut self) -> ObjectBuilder<'_, Self::State<'_>>
 
fn new_object(&mut self) -> ObjectBuilder<'_, Self::State<'_>>
Creates a nested object builder. See e.g. [
VariantBuilder::new_object]. Panics if the
nested builder cannot be created, see e.g. [ObjectBuilder::new_object].Auto Trait Implementations§
impl !Freeze for VariantArrayBuilder
impl RefUnwindSafe for VariantArrayBuilder
impl Send for VariantArrayBuilder
impl Sync for VariantArrayBuilder
impl Unpin for VariantArrayBuilder
impl UnwindSafe for VariantArrayBuilder
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
§impl<T> JsonToVariant for Twhere
    T: VariantBuilderExt,
 
impl<T> JsonToVariant for Twhere
    T: VariantBuilderExt,
§fn append_json(&mut self, json: &str) -> Result<(), ArrowError>
 
fn append_json(&mut self, json: &str) -> Result<(), ArrowError>
Create a Variant from a JSON string