alamb commented on issue #7870:
URL: https://github.com/apache/arrow-rs/issues/7870#issuecomment-3038776720

   > 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:
   ```rust
   let mut builder = VariantBuilder::new();
   // store the offsets of the variants created
   let mut 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 variant
     convert_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 🤔 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to