You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "friendlymatthew (via GitHub)" <gi...@apache.org> on 2025/07/11 22:50:44 UTC

[PR] Append complex variants [arrow-rs]

friendlymatthew opened a new pull request, #7914:
URL: https://github.com/apache/arrow-rs/pull/7914

   # Which issue does this PR close?
   
   - Fixes https://github.com/apache/arrow-rs/issues/7907
   
   # Rationale for this change
   
   When trying to append `VariantObject` or `VariantList`s directly on the `VariantBuilder`, it will panic. 
   


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3079918834

   What I suggest doing is looking into changing the `PartialEq` implementaion for Variant to implement "logical: equality rather than physical equality
   
   So rather than the `#derived` implementaiton of PartialEQ, which will check equality of underyling bytes, recursively check the variant and its children
   
   I am not 100% sure what the semantics should be for field name order 


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Append complex variants [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#discussion_r2202872795


##########
parquet-variant/src/builder.rs:
##########
@@ -2170,4 +2251,45 @@ mod tests {
         let variant = Variant::try_new_with_metadata(metadata, &value).unwrap();
         assert_eq!(variant, Variant::Int8(2));
     }
+
+    #[test]
+    fn test_append_object() {
+        let (m1, v1) = make_object();
+        let variant = Variant::new(&m1, &v1);
+
+        let mut builder = VariantBuilder::new();
+        builder.append_value(variant.clone());
+        let (metadata, value) = builder.finish();
+        assert_eq!(variant, Variant::new(&metadata, &value));
+    }
+
+    /// make an object variant
+    fn make_object() -> (Vec<u8>, Vec<u8>) {
+        let mut builder = VariantBuilder::new();
+
+        let mut obj = builder.new_object();
+        obj.insert("a", true);
+        obj.finish().unwrap();
+        builder.finish()
+    }
+
+    #[test]
+    fn test_append_list() {

Review Comment:
   I suggest also adding a test with more than one level of nesting (aka a list of objects) to make sure the recursion works correctly



##########
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:
   WHy not call `self.append_variant_object` and `self.append_variant_list` here (to avoid the panic?)



##########
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>) {

Review Comment:
   As a user I don't want to have to already have a `VariantObject` when appending -- I would like to just append the `Variant` directly.
   
   I suggest we keep `append_object, `try_append_object`, `append_list` and `try_append_list` as implementation detail (aka a non `pub` method)



##########
parquet-variant/src/builder.rs:
##########
@@ -707,7 +782,13 @@ impl VariantBuilder {
     /// builder.append_value(42i8);
     /// ```
     pub fn append_value<'m, 'd, T: Into<Variant<'m, 'd>>>(&mut self, value: T) {
-        self.buffer.append_non_nested_value(value);
+        let variant = value.into();
+
+        match variant {
+            Variant::Object(obj) => self.append_object(obj),

Review Comment:
   Yes, I agree -- I thik it would make a lot of sense to have a `try_append_value` that returns an error (rather than panic'ing) if an invalid variant is passed in.
   Then `append_value` would just call `self try_append_value(v).unwrap()` 🤔 
   



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "friendlymatthew (via GitHub)" <gi...@apache.org>.
friendlymatthew commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3078243701

   Hi, round tripping variant objects would fail because we were writing out object field names by the sort order. This is fine for variants with a sorted dictionary, but everything else will produce inconsistent results
   
   What we want instead is to write out the object fields by insertion order, we can do this by passing in the `VariantMetadata` ahead of time. This way we know the insertion order of field names
   
   I'm sure we can improve the implementation, but it is correct
   
   cc @alamb 
   


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "Samyak2 (via GitHub)" <gi...@apache.org>.
Samyak2 commented on code in PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#discussion_r2211309113


##########
parquet-variant/src/builder.rs:
##########
@@ -239,12 +279,38 @@ 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"
-                );
+            Variant::Object(obj) => {
+                let metadata_field_names = metadata_builder
+                    .field_names
+                    .iter()
+                    .enumerate()
+                    .map(|(i, f)| (f.clone(), i))
+                    .collect::<HashMap<_, _>>();
+
+                let mut object_builder = self.new_object(metadata_builder);
+
+                // first add all object fields that exist in metadata builder

Review Comment:
   +1 for the logical equality function on variants. This will be needed in tests where the result and expected variants come from different sources (and thus might have a mismatch in metadata or ordering).



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3070884532

   I am starting to hack in this a bit


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3079906213

   > I will have time for the next hour so I would like to clean up
   
   Awesome -- maybe a follow on PR!


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3079896370

   Let's get this in and keep iterating


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3079856984

   > Sorry for the awolness, I am fighting jet lag/conferences
   
   
   No worries at all -- I think we are all struggling to find the time while juggling many other things. It is totally fine -- and the nature of open source work


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3079922555

   I think accoding to my reading of https://github.com/apache/parquet-format/blob/master/VariantEncoding.md#value-data-for-object-basic_type2, the field order can vary from objet to object so when comparing two variants for equality the field order should not be taken into account


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3079898448

   (BTW @friendlymatthew if you are willing, if you make PRs from your own personal fork, rather than the pydantic one, I can push commits directly to the PR, which might speed up development)


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "friendlymatthew (via GitHub)" <gi...@apache.org>.
friendlymatthew commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3079659412

   > I think this is the most important Variant PR at the moment from my perspective as we will likely need this for many of the other things we are discussing.
   > 
   > 
   > 
   > Thus I plan to help with this one first and then move on to more shredding related ones
   > 
   > 
   > 
   > @friendlymatthew please let me know if you get stuck or need some help. Otherwise I'll wait for a ping from you
   
   Hi, I'm curious to get your thoughts.
   
   Sorry for the awolness, I am fighting jet lag/conferences
   
   Cc @scovich 
   


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3070228702

   I think this PR unlocks several other APIs so I hope to spend some time helping it along later today


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Append complex variants [arrow-rs]

Posted by "abacef (via GitHub)" <gi...@apache.org>.
abacef commented on code in PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#discussion_r2202086488


##########
parquet-variant/src/builder.rs:
##########
@@ -707,7 +782,13 @@ impl VariantBuilder {
     /// builder.append_value(42i8);
     /// ```
     pub fn append_value<'m, 'd, T: Into<Variant<'m, 'd>>>(&mut self, value: T) {
-        self.buffer.append_non_nested_value(value);
+        let variant = value.into();
+
+        match variant {
+            Variant::Object(obj) => self.append_object(obj),

Review Comment:
   Should we create a clone of this `append_value` function using the `try_append` functions



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "scovich (via GitHub)" <gi...@apache.org>.
scovich commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3084880291

   > I think accoding to my reading of https://github.com/apache/parquet-format/blob/master/VariantEncoding.md#value-data-for-object-basic_type2, the field order can vary from objet to object so when comparing two variants for equality the field order should not be taken into account
   
   I thought the fields (as in, the field id array) _did_ need to be in (lexical) order? The corresponding value bytes can be out of order but hopefully their physical placement doesn't change the logical equality test. 
   
   One observation tho -- an unordered metadata dictionary can have duplicate field ids. Two fields have the same name if their field ids are the same, but field ids differing does _NOT_ prove that the fields have different names.


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "friendlymatthew (via GitHub)" <gi...@apache.org>.
friendlymatthew commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3079977638

   > the field order can vary from objet to object so when comparing two variants for equality the field order should not be taken into account
   
   Hm, I assume you are talking about 
   
   >  The field ids and field offsets must be in lexicographical order of the corresponding field names in the metadata dictionary.
   > However, the actual `value` entries do not need to be in any particular order.
   > This implies that the `field_offset` values may not be monotonically increasing.
   > For example, for the following object:
   > ```
   > {
   >   "c": 3,
   >   "b": 2,
   >   "a": 1
   > }
   > ```
   > The `field_id` list must be `[<id for key "a">, <id for key "b">, <id for key "c">]`, in lexicographical order.
   > The `field_offset` list must be `[<offset for value 1>, <offset for value 2>, <offset for value 3>, <last offset>]`.
   > The `value` list can be in any order.


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "friendlymatthew (via GitHub)" <gi...@apache.org>.
friendlymatthew commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3079946469

   > (BTW @friendlymatthew if you are willing, if you make PRs from your own personal fork, rather than the pydantic one, I can push commits directly to the PR, which might speed up development)
   
   Ah sounds good. I haven't checked recently, but I noticed pushing up PRs from my fork requires approval to run CI which was kind of a pain
   


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Append complex variants [arrow-rs]

Posted by "friendlymatthew (via GitHub)" <gi...@apache.org>.
friendlymatthew commented on code in PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#discussion_r2202020955


##########
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"),
         }
     }
 
+    fn append_non_nested_value<'m, 'd, T: Into<Variant<'m, 'd>>>(&mut self, value: T) {

Review Comment:
   maybe a better name would be `append_primitive_value`? 



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3074866005

   I think this is the most important Variant PR at the moment from my perspective as we will likely need this for many of the other things we are discussing.
   
   Thus I plan to help with this one first and then move on to more shredding related ones
   
   @friendlymatthew please let me know if you get stuck or need some help. Otherwise I'll wait for a ping from you


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Append complex variants [arrow-rs]

Posted by "abacef (via GitHub)" <gi...@apache.org>.
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#discussion_r2211289684


##########
parquet-variant/src/builder.rs:
##########
@@ -310,6 +376,8 @@ impl MetadataBuilder {
     fn upsert_field_name(&mut self, field_name: &str) -> u32 {
         let (id, new_entry) = self.field_names.insert_full(field_name.to_string());
 
+        dbg!(new_entry);

Review Comment:
   I think this is left over



##########
parquet-variant/src/builder.rs:
##########
@@ -239,12 +279,38 @@ 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"
-                );
+            Variant::Object(obj) => {
+                let metadata_field_names = metadata_builder
+                    .field_names
+                    .iter()
+                    .enumerate()
+                    .map(|(i, f)| (f.clone(), i))
+                    .collect::<HashMap<_, _>>();
+
+                let mut object_builder = self.new_object(metadata_builder);
+
+                // first add all object fields that exist in metadata builder

Review Comment:
   I see the code here is basically trying to preserve the order so that the variants compare deeply equal
   
   Rather than trying to preserve the byte-for-byte equality here, I think a better idea could be to implement a `Variant::eq_value` type method that compares the Variants for logical equality, rather than byte-for-byte equality.
   
   I am thinking we can merge this PR and then I will make a follow on PR for that idea



-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3085054997

   > One observation tho -- an unordered metadata dictionary can have duplicate field ids. Two fields have the same name if their field ids are the same, but field ids differing does _NOT_ prove that the fields have different names.
   
   I think @friendlymatthew  correctly implemented these semantics in https://github.com/apache/arrow-rs/pull/7943


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "friendlymatthew (via GitHub)" <gi...@apache.org>.
friendlymatthew commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3070237651

   > I think this PR unlocks several other APIs so I hope to spend some time helping it along later today
   
   Hi, I am traveling today so I've been a bit preoccupied. I'll try to get this over the line during my flight.


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "friendlymatthew (via GitHub)" <gi...@apache.org>.
friendlymatthew commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3079899471

   > Thank you @friendlymatthew  -- I think there are several things to improve in this PR (such as `dbg!` and the need to sort the fields for appending) -- however in order to keep things moving I will merge this one as is and then make a follow on PR or ticket to improve 
   
   I will have time for the next hour so I would like to clean up


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "scovich (via GitHub)" <gi...@apache.org>.
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "friendlymatthew (via GitHub)" <gi...@apache.org>.
friendlymatthew commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3072965259

   Hi, I pushed up some cases that fail. The ordering of field names are getting mixed up when roundtripping. 
   
   I'll continue to take a look.


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3079922698

   Does that make sense?


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Variant] Support appending complex variants in `VariantBuilder` [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #7914:
URL: https://github.com/apache/arrow-rs/pull/7914#issuecomment-3080101465

   > Ah sounds good. I haven't checked recently, but I noticed pushing up PRs from my fork requires approval to run CI which was kind of a pain
   
   This happens for first time contributors. Once we have merged a PR from your CI will run automatically
   
   I think since we have now merged several your CI runs should go automatically


-- 
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-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org