scovich commented on code in PR #7915:
URL: https://github.com/apache/arrow-rs/pull/7915#discussion_r2202825775


##########
parquet-variant/src/builder.rs:
##########
@@ -835,18 +936,23 @@ impl<'a> ObjectBuilder<'a> {
     ///
     /// Note: when inserting duplicate keys, the new value overwrites the 
previous mapping,
     /// but the old value remains in the buffer, resulting in a larger variant
-    pub fn insert<'m, 'd, T: Into<Variant<'m, 'd>>>(&mut self, key: &str, 
value: T) {
+    pub fn insert<'m, 'd, T: Into<Variant<'m, 'd>>>(
+        &mut self,
+        key: &str,
+        value: T,
+    ) -> Result<(), ArrowError> {
         // Get metadata_builder from parent state
         let metadata_builder = self.parent_state.metadata_builder();
 
-        let field_id = metadata_builder.upsert_field_name(key);
+        let field_id = metadata_builder.upsert_field_name(key)?;
         let field_start = self.buffer.offset();
 
         if self.fields.insert(field_id, field_start).is_some() && 
self.validate_unique_fields {
             self.duplicate_fields.insert(field_id);
         }

Review Comment:
   Now that `insert` is fallible, we can fail-fast instead of tracking a set of 
duplicate fields for `finish` to worry about:
   ```suggestion
           if self.fields.insert(field_id, field_start).is_some() && 
self.validate_unique_fields {
               return Err(... duplicate field {key} ...);
           }
   ```



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