VariantArrayBuilder

Struct VariantArrayBuilder 

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

  1. 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();

// create the final VariantArray
let variant_array = builder.build();
assert_eq!(variant_array.len(), 3);
// // 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")));

Fields§

§nulls: NullBufferBuilder§metadata_builder: WritableMetadataBuilder§metadata_offsets: Vec<usize>§value_builder: ValueBuilder§value_offsets: Vec<usize>§fields: Fields

Implementations§

§

impl VariantArrayBuilder

pub fn new(row_capacity: usize) -> VariantArrayBuilder

pub fn build(self) -> VariantArray

Build the final builder

pub fn append_null(&mut self)

Appends a null row to the builder.

pub fn append_variant(&mut self, variant: Variant<'_, '_>)

Append the Variant to the builder as the next row

Trait Implementations§

§

impl Debug for VariantArrayBuilder

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl VariantBuilderExt for VariantArrayBuilder

§

fn append_null(&mut self)

Appending NULL to a variant array produces an actual NULL value

§

type State<'a> = ArrayBuilderState<'a> where VariantArrayBuilder: 'a

The builder specific state used by nested builders
§

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

fn try_new_list( &mut self, ) -> Result<ListBuilder<'_, <VariantArrayBuilder as VariantBuilderExt>::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.
§

fn try_new_object( &mut self, ) -> Result<ObjectBuilder<'_, <VariantArrayBuilder as VariantBuilderExt>::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<'_>>

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<'_>>

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§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> JsonToVariant for T

§

fn append_json(&mut self, json: &str) -> Result<(), ArrowError>

Create a Variant from a JSON string
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> Ungil for T
where T: Send,