friendlymatthew commented on code in PR #7801:
URL: https://github.com/apache/arrow-rs/pull/7801#discussion_r2173769129


##########
parquet-variant/src/builder.rs:
##########
@@ -605,17 +627,30 @@ impl<'a, 'b> ObjectBuilder<'a, 'b> {
         let field_id = self.metadata_builder.upsert_field_name(key);
         let field_start = self.buffer.offset();
 
-        self.fields.insert(field_id, field_start);
+        if self.fields.insert(field_id, field_start).is_some() && 
self.validate_duplicates {
+            self.duplicate_fields.insert(field_id);
+        }
+
         self.buffer.append_non_nested_value(value);
     }
 
+    /// Enables validation for duplicate field keys when inserting into this 
object.
+    /// 
+    /// When this is enabled, calling [`ObjectBuilder::finish`] will return an 
error
+    /// if any duplicate field keys were added using [`ObjectBuilder::insert`].
+    pub fn with_validate_unique_fields(mut self) -> Self {
+        self.validate_duplicates = true;
+        self
+    }
+
     /// Return a new [`ObjectBuilder`] to add a nested object with the 
specified
     /// key to the object.
     pub fn new_object(&mut self, key: &'b str) -> ObjectBuilder {
         self.check_pending_field();
 
         let field_start = self.buffer.offset();
-        let obj_builder = ObjectBuilder::new(&mut self.buffer, 
self.metadata_builder);
+        let mut obj_builder = ObjectBuilder::new(&mut self.buffer, 
self.metadata_builder);
+        obj_builder.validate_duplicates = self.validate_duplicates;

Review Comment:
   Since we have `ObjectBuilder::with_validate_unique_fields` and if we update 
the function header to take in a flag parameter, we can chain these together. 
   
   Something like: 
   
   ```rs
   let obj_builder = ObjectBuilder::new(&mut self.buffer, self.metadata_builder)
        .with_validate_unique_fields(self.validate_duplicates);
   ```



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