Struct VariantArrayBuilder

Source
pub struct VariantArrayBuilder {
    nulls: NullBufferBuilder,
    metadata_buffer: Vec<u8>,
    metadata_locations: Vec<(usize, usize)>,
    value_buffer: Vec<u8>,
    value_locations: Vec<(usize, 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
builder.append_null();
// append a pre-constructed metadata and value buffers
let (metadata, value) = {
  let mut vb = VariantBuilder::new();
  let mut obj = vb.new_object();
  obj.insert("foo", "bar");
  obj.finish().unwrap();
  vb.finish()
};
builder.append_variant_buffers(&metadata, &value);

// 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));
assert!(variant_array.value(2).as_object().is_some());

Fields§

§nulls: NullBufferBuilder

Nulls

§metadata_buffer: Vec<u8>

buffer for all the metadata

§metadata_locations: Vec<(usize, usize)>

(offset, len) pairs for locations of metadata in the buffer

§value_buffer: Vec<u8>

buffer for values

§value_locations: Vec<(usize, usize)>

(offset, len) pairs for locations of values in the buffer

§fields: Fields

The fields of the final StructArray

TODO: 1) Add extension type metadata TODO: 2) Add support for shredding

Implementations§

Source§

impl VariantArrayBuilder

Source

pub fn new(row_capacity: usize) -> Self

Source

pub fn build(self) -> VariantArray

Build the final builder

Source

pub fn append_null(&mut self)

Appends a null row to the builder.

Source

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

Append the [Variant] to the builder as the next row

Source

pub fn append_variant_buffers(&mut self, metadata: &[u8], value: &[u8])

Append a metadata and values buffer to the builder

Trait Implementations§

Source§

impl Debug for VariantArrayBuilder

Source§

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

Formats the value using the given formatter. Read more

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, 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> Ungil for T
where T: Send,