alamb commented on code in PR #8167:
URL: https://github.com/apache/arrow-rs/pull/8167#discussion_r2287735370


##########
parquet-variant/src/builder.rs:
##########
@@ -1428,54 +1415,61 @@ impl<'a> ObjectBuilder<'a> {
     }
 
     // Returns validate_unique_fields because we can no longer reference self 
once this method returns.
-    fn parent_state<'b>(&'b mut self, key: &'b str) -> (ParentState<'b>, bool) 
{
+    fn parent_state<'b>(
+        &'b mut self,
+        field_name: &'b str,
+    ) -> Result<(ParentState<'b>, bool), ArrowError> {
+        let saved_parent_buffer_offset = 
self.parent_state.saved_buffer_offset();
         let validate_unique_fields = self.validate_unique_fields;
-
         let (buffer, metadata_builder) = 
self.parent_state.buffer_and_metadata_builder();
-
-        let state = ParentState::Object {
+        let state = ParentState::object(
             buffer,
             metadata_builder,
-            fields: &mut self.fields,
-            field_name: key,
-            parent_value_offset_base: self.parent_value_offset_base,
-        };
-        (state, validate_unique_fields)
+            &mut self.fields,
+            saved_parent_buffer_offset,
+            field_name,
+            validate_unique_fields,
+        )?;
+        Ok((state, validate_unique_fields))
     }
 
     /// Returns an object builder that can be used to append a new (nested) 
object to this object.
     ///
+    /// Panics if the requested key cannot be inserted (e.g. because it is a 
duplicate).

Review Comment:
   > Plus, it always seemed weird to do extra work to defer an obvious known 
failure until later. Is there a disadvantage to failing immediately?
   
   the only disadvantage is that it is annoying if you have to do error 
checking for operations that can't fail - like making a new object with owned 
metadata. 



-- 
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]

Reply via email to