abacef commented on code in PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#discussion_r2202076714
##########
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>(
+ &mut self,
+ object: VariantObject<'m, 'v>,
+ ) -> Result<(), ArrowError> {
+ let (parent_state, validate_unique_fields) = self.parent_state();
+
+ let mut obj_builder = ObjectBuilder::new(parent_state,
validate_unique_fields);
+
+ for res in object.iter_try() {
+ let (field_name, variant) = res?;
+
+ obj_builder.insert(field_name, variant);
+ }
+
+ obj_builder.finish()?;
+
+ Ok(())
+ }
+
+ /// Appends a [`VariantList`] to the builder.
+ ///
+ /// # Panics
+ /// Will panic if any nested validation fails during list iteration.
+ /// Use `try_append_list` if you need full validation for untrusted data.
+ pub fn append_list<'m, 'v>(&mut self, list: VariantList<'m, 'v>) {
+ let (parent_state, validate_unique_fields) = self.parent_state();
+
+ let mut list_builder = ListBuilder::new(parent_state,
validate_unique_fields);
+
+ for variant in list.iter() {
+ list_builder.append_value(variant);
+ }
+
+ list_builder.finish();
+ }
+
+ /// Appends a [`VariantList`] to the builder with full validation during
iteration.
+ ///
+ /// Recursively validates all nested variants in the list during iteration.
+ pub fn try_append_list<'m, 'v>(&mut self, list: VariantList<'m, 'v>) ->
Result<(), ArrowError> {
+ let (parent_state, validate_unique_fields) = self.parent_state();
+
+ let mut list_builder = ListBuilder::new(parent_state,
validate_unique_fields);
+
+ for variant in list.iter_try() {
+ list_builder.append_value(variant?);
+ }
+
+ list_builder.finish();
+
+ Ok(())
+ }
+
/// Append a non-nested value to the builder.
Review Comment:
You may need to remove `non-nested`
--
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]