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
impl VariantValueArrayBuilder
pub fn new(row_capacity: usize) -> 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>
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)
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<'_, '_>)
pub fn append_value(&mut self, value: Variant<'_, '_>)
Append a variant value with its corresponding metadata
§Arguments
value
- The variant value to appendmetadata
- The metadata dictionary for this variant (used for field name resolution)
§Returns
Ok(())
if the value was successfully appendedErr(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>>
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>
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§
Auto Trait Implementations§
impl !Freeze for VariantValueArrayBuilder
impl RefUnwindSafe for VariantValueArrayBuilder
impl Send for VariantValueArrayBuilder
impl Sync for VariantValueArrayBuilder
impl Unpin for VariantValueArrayBuilder
impl UnwindSafe for VariantValueArrayBuilder
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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