scovich commented on code in PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#discussion_r2202823069
##########
parquet-variant/src/builder.rs:
##########
@@ -213,14 +215,14 @@ impl ValueBuffer {
Variant::Binary(v) => self.append_binary(v),
Variant::String(s) => self.append_string(s),
Variant::ShortString(s) => self.append_short_string(s),
- Variant::Object(_) | Variant::List(_) => {
- unreachable!(
- "Nested values are handled specially by ObjectBuilder and
ListBuilder"
- );
- }
+ _ => unreachable!("Objects and lists must be appended using
VariantBuilder::append_object and VariantBuilder::append_list"),
Review Comment:
This is an awkward division of responsibilities. What if we got rid of
`ValueBuffer::append_variant` entirely, and just had the builder invoke the
primitive `append_xxx` methods directly?
##########
parquet-variant/src/builder.rs:
##########
@@ -213,14 +215,14 @@ impl ValueBuffer {
Variant::Binary(v) => self.append_binary(v),
Variant::String(s) => self.append_string(s),
Variant::ShortString(s) => self.append_short_string(s),
- Variant::Object(_) | Variant::List(_) => {
- unreachable!(
- "Nested values are handled specially by ObjectBuilder and
ListBuilder"
- );
- }
+ _ => unreachable!("Objects and lists must be appended using
VariantBuilder::append_object and VariantBuilder::append_list"),
Review Comment:
I guess the method is currently important because all three builders need to
call it. I wonder more and more whether there might be some way to harmonize
the implementations more, leveraging a combination of `ParentState` and
`VariantBuilderExt`?
##########
parquet-variant/src/builder.rs:
##########
@@ -697,6 +699,79 @@ impl VariantBuilder {
ObjectBuilder::new(parent_state, validate_unique_fields)
}
+ /// Appends a [`VariantObject`] to the builder.
+ ///
+ /// # Panics
+ /// Will panic if the appended object has duplicate field names or any
nested validation fails.
+ /// Use `try_append_object` if you need full validation for untrusted data.
+ pub fn append_object<'m, 'v>(&mut self, object: VariantObject<'m, 'v>) {
+ let (parent_state, validate_unique_fields) = self.parent_state();
+
+ let mut obj_builder = ObjectBuilder::new(parent_state,
validate_unique_fields);
+
+ for (field_name, variant) in object.iter() {
+ obj_builder.insert(field_name, variant);
+ }
+
+ obj_builder.finish().unwrap();
+ }
+
+ /// Appends a [`VariantObject`] to the builder with full validation during
iteration.
+ ///
+ /// Recursively validates all nested variants in the object during
iteration.
+ pub fn try_append_object<'m, 'v>(
Review Comment:
I wish there were an efficient way to reuse code for fallible vs. infallible
versions of this method...
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]