You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it looks like the variant builder allows to "append" any number of variant values -- almost a column-oriented builder concept, but lacking any mechanism for tracking objects and the boundaries between them.
It almost seems like the top-level VariantBuilder shouldn't even exist:
For any primitive value, Variant::from the input should work
For list and object values, perhaps we need a way to construct a list or object builder directly
The one thing VariantBuilderdoes provide is the handling of separate metadata + value buffers. But that just proves the current "append as many values as you like" API is incorrect -- each top-level variant value in a column of variant values needs its own metadata value -- not one aggregate metadata value for the whole column.
The one thing VariantBuilder does provide is the handling of separate metadata + value buffers. But that just proves the current "append as many values as you like" API is incorrect -- each top-level variant value in a column of variant values needs its own metadata value -- not one aggregate metadata value for the whole column.
I think this is an important usecase (it is possible / allowed for the variant value stored in a row to be non nested)
Also, it turns out you can finish a VariantBuilder without ever appending anything to it, which is also bad (produces an empty value buffer).
I think an important usecase for VariantBuilder is to convert a column of an existing type (e.g. json strings, ints, etc) into a column of varaint values. Something like:
letmut builder = VariantBuilder::new();// store the offsets of the variants createdletmut offsets = vec[];for row in rows {// record where the current variant starts (THIS API DOES NOT EXIST YET)
offsets.push(builder.current_offset());// convert the row to a variantconvert_row_to_variant(&mut builder, row))?
}
Maybe in addition to the metadata and values, VariantBuilder itself should store the offsets of each of the created variants 🤔
I think an important usecase for VariantBuilder is to convert a column of an existing type (e.g. json strings, ints, etc) into a column of varaint values.
Maybe in addition to the metadata and values, VariantBuilder itself should store the offsets of each of the created variants 🤔
... that could work, but only if it also creates one metadata dictionary per variant value and tracks those offsets as well:
The one thing VariantBuilderdoes provide is the handling of separate metadata + value buffers. But that just proves the current "append as many values as you like" API is incorrect -- each top-level variant value in a column of variant values needs its own metadata value -- not one aggregate metadata value for the whole column.
... at which point it's no longer meaningful to provide a finish method. Instead, an into_parts method would consume self and return all four building blocks, which a caller could then assemble into a StructArray of BinaryArray.
... that could work, but only if it also creates one metadata dictionary per variant value and tracks those offsets as well:
We probably want to make sure we can share the metadata across rows if desired (so in other words I don't think it should require starting a new metadata...)
I suggest we postpone any more API changes here until we start working on actual variant cast kernels 🤔
Maybe we could start with one we know we will likely want
/// Converts a StringArray, LargeStringArray or StringViewArray that contains/// JSON formatted text into a Struct array containing a Parquet Variantjson_to_variant_array(arr:ArrayRef) -> Result<StructArray> {
...}
I think that will also force us to figure out what kind of arrays will be supported
We probably want to make sure we can share the metadata across rows if desired (so in other words I don't think it should require starting a new metadata...)
That's tricky, because we don't know, at the time we start a new variant, whether it will add new field names and/or use all existing ones. From a parquet dictionary encoding perspective, it's attractive to use one/few byte-identical metadata dictionaries for the whole column. But getting it wrong could bloat things really badly.
I suggest we postpone any more API changes here until we start working on actual variant cast kernels 🤔
That's tricky, because we don't know, at the time we start a new variant, whether it will add new field names and/or use all existing ones. From a parquet dictionary encoding perspective, it's attractive to use one/few byte-identical metadata dictionaries for the whole column. But getting it wrong could bloat things really badly.
I agree the writer will have to be clever and there is room for substantial tradeoffs (like slower write / better encoding / more memory usage).
What I suggest is that we have all the low level APIs needed (aka allow the caller to decide if they want to create new metadata, or if they want to keep using the same one even though it might be bloated, etc)
Activity
[-]VariantBuilder accepts multiple variant values[/-][+]VariantBuilder (wrongly?) accepts multiple variant values[/+]scovich commentedon Jul 4, 2025
It almost seems like the top-level
VariantBuildershouldn't even exist:Variant::fromthe input should workThe one thing
VariantBuilderdoes provide is the handling of separate metadata + value buffers. But that just proves the current "append as many values as you like" API is incorrect -- each top-level variant value in a column of variant values needs its own metadata value -- not one aggregate metadata value for the whole column.[-]VariantBuilder (wrongly?) accepts multiple variant values[/-][+]VariantBuilder (wrongly?) accepts 0+ variant values[/+]scovich commentedon Jul 4, 2025
Also, it turns out you can
finishaVariantBuilderwithout ever appending anything to it, which is also bad (produces an emptyvaluebuffer).alamb commentedon Jul 5, 2025
I think this is an important usecase (it is possible / allowed for the variant value stored in a row to be non nested)
I think an important usecase for
VariantBuilderis to convert a column of an existing type (e.g. json strings, ints, etc) into a column of varaint values. Something like:Maybe in addition to the
metadataandvalues,VariantBuilderitself should store the offsets of each of the created variants 🤔[-]VariantBuilder (wrongly?) accepts 0+ variant values[/-][+][Variant] VariantBuilder (wrongly?) accepts 0+ variant values[/+]scovich commentedon Jul 5, 2025
... that could work, but only if it also creates one metadata dictionary per variant value and tracks those offsets as well:
... at which point it's no longer meaningful to provide a
finishmethod. Instead, aninto_partsmethod would consumeselfand return all four building blocks, which a caller could then assemble into aStructArrayofBinaryArray.Careful tho --
BinaryArrayusesi32offsets while variant usesu32!alamb commentedon Jul 5, 2025
We probably want to make sure we can share the metadata across rows if desired (so in other words I don't think it should require starting a new metadata...)
I suggest we postpone any more API changes here until we start working on actual variant cast kernels 🤔
Maybe we could start with one we know we will likely want
I think that will also force us to figure out what kind of arrays will be supported
For example is it
Or
Or something else
scovich commentedon Jul 5, 2025
Shredding will add/allow an arbitrary-typed
typed_valuefield as well...scovich commentedon Jul 5, 2025
That's tricky, because we don't know, at the time we start a new variant, whether it will add new field names and/or use all existing ones. From a parquet dictionary encoding perspective, it's attractive to use one/few byte-identical metadata dictionaries for the whole column. But getting it wrong could bloat things really badly.
Fair.
alamb commentedon Jul 5, 2025
I agree the writer will have to be clever and there is room for substantial tradeoffs (like slower write / better encoding / more memory usage).
What I suggest is that we have all the low level APIs needed (aka allow the caller to decide if they want to create new metadata, or if they want to keep using the same one even though it might be bloated, etc)
sdf-jkl commentedon May 25, 2026
@alamb @scovich what do you think is a better idea?
Keep
impl ValueBuilder {pub fn finish(mut self) -> (Vec<u8>, Vec<u8>) {and panicvs
pub fn finish(mut self) -> Result<(Vec<u8>, Vec<u8>), ArrowError> {alamb commentedon May 26, 2026
I think we should mirror other APIs (where I think there is both a ressult and non result API)
Mabe something like
[Variant] Add `VariantBuilder` values check (#10016)