VariantValueArrayBuilder

Struct VariantValueArrayBuilder 

pub struct VariantValueArrayBuilder {
    value_builder: ValueBuilder,
    value_offsets: Vec<usize>,
    nulls: NullBufferBuilder,
}
Expand description

A builder for creating only the value column of a VariantArray

This builder is used when you have existing metadata and only need to build the value column. It’s useful for scenarios like variant unshredding, data transformation, or filtering where you want to reuse existing metadata.

The builder produces a [BinaryViewArray] that can be combined with existing metadata to create a complete VariantArray.

§Example:

// Create a variant value builder for 10 rows
let mut builder = VariantValueArrayBuilder::new(10);

// Append some values with their corresponding metadata, which the
// builder takes advantage of to avoid creating new metadata.
builder.append_value(Variant::from(42));
builder.append_null();
builder.append_value(Variant::from("hello"));

// Build the final value array
let value_array = builder.build().unwrap();
assert_eq!(value_array.len(), 3);

Fields§

§value_builder: ValueBuilder§value_offsets: Vec<usize>§nulls: NullBufferBuilder

Implementations§

§

impl VariantValueArrayBuilder

pub fn new(row_capacity: usize) -> VariantValueArrayBuilder

Create a new VariantValueArrayBuilder with the specified row capacity

pub fn build(self) -> Result<GenericByteViewArray<BinaryViewType>, ArrowError>

Build the final value array

Returns a [BinaryViewArray] containing the serialized variant values. This can be combined with existing metadata to create a complete VariantArray.

pub fn append_null(&mut self)

Append a null row to the builder

WARNING: It is only valid to call this method when building the value field of a shredded variant column (which is nullable). The value field of a binary (unshredded) variant column is non-nullable, and callers should instead invoke Self::append_value with Variant::Null, passing the appropriate metadata value.

pub fn append_value(&mut self, value: Variant<'_, '_>)

Append a variant value with its corresponding metadata

§Arguments
  • value - The variant value to append
  • metadata - The metadata dictionary for this variant (used for field name resolution)
§Returns
  • Ok(()) if the value was successfully appended
  • Err(ArrowError) if the variant contains field names not found in the metadata
§Example
let mut builder = VariantValueArrayBuilder::new(10);
builder.append_value(Variant::from(42));

pub fn parent_state<'a>( &'a mut self, metadata_builder: &'a mut dyn MetadataBuilder, ) -> ParentState<'a, ValueArrayBuilderState<'a>>

Creates a builder-specific parent state.

For example, this can be useful for code that wants to copy a subset of fields from an object value as a new row of value_array_builder:

let Variant::Object(obj) = value else {
    panic!("Not a variant object");
};
let mut metadata_builder = ReadOnlyMetadataBuilder::new(&obj.metadata);
let state = value_array_builder.parent_state(&mut metadata_builder);
let mut object_builder = ObjectBuilder::new(state, false);
for (field_name, field_value) in obj.iter() {
    if should_keep(field_name) {
        object_builder.insert_bytes(field_name, field_value);
    }
}
 object_builder.finish(); // appends the filtered object

pub fn builder_ext<'a>( &'a mut self, metadata: &'a VariantMetadata<'a>, ) -> VariantValueArrayBuilderExt<'a>

Creates a thin VariantBuilderExt wrapper for this builder, which hides the metadata parameter (similar to the way parquet_variant::ObjectFieldBuilder hides field names).

Trait Implementations§

§

impl Debug for VariantValueArrayBuilder

§

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

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> 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
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,