This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new a85d8b0256 [Variant] impl `PartialEq` and `FromIterator<Option<..>>` 
for `VariantArray` (#8627)
a85d8b0256 is described below

commit a85d8b025610ad7eea2266cb4ac383f7fd0c767e
Author: Matthew Kim <[email protected]>
AuthorDate: Fri Oct 17 14:07:15 2025 -0400

    [Variant] impl `PartialEq` and `FromIterator<Option<..>>` for 
`VariantArray` (#8627)
    
    # Which issue does this PR close?
    
    - Closes https://github.com/apache/arrow-rs/issues/8610
    
    # Rationale for this change
    
    Since the fields of `VariantArray` impl `PartialEq`, this PR simply
    derives `PartialEq` for `VariantArray`
    out.
    
    Based off of https://github.com/apache/arrow-rs/pull/8625
---
 parquet-variant-compute/src/variant_array.rs | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/parquet-variant-compute/src/variant_array.rs 
b/parquet-variant-compute/src/variant_array.rs
index 6ce84f232a..2b38081d07 100644
--- a/parquet-variant-compute/src/variant_array.rs
+++ b/parquet-variant-compute/src/variant_array.rs
@@ -208,7 +208,7 @@ impl ExtensionType for VariantType {
 /// assert_eq!(variant_array.value(0), Variant::from("such wow"));
 /// ```
 ///
-#[derive(Clone, Debug)]
+#[derive(Debug, Clone, PartialEq)]
 pub struct VariantArray {
     /// Reference to the underlying StructArray
     inner: StructArray,
@@ -741,7 +741,7 @@ impl From<ShreddedVariantFieldArray> for StructArray {
 /// (partial shredding).
 ///
 /// [Parquet Variant Shredding Spec]: 
https://github.com/apache/parquet-format/blob/master/VariantShredding.md#value-shredding
-#[derive(Clone, Debug)]
+#[derive(Debug, Clone, PartialEq)]
 pub struct ShreddingState {
     value: Option<BinaryViewArray>,
     typed_value: Option<ArrayRef>,
@@ -1467,4 +1467,27 @@ mod test {
             Variant::ShortString(ShortString::try_new("norm").unwrap())
         );
     }
+
+    #[test]
+    fn test_variant_equality() {
+        let v_iter = [None, Some(Variant::BooleanFalse), Some(Variant::Null), 
None];
+        let v = VariantArray::from_iter(v_iter.clone());
+
+        {
+            let v_copy = v.clone();
+            assert_eq!(v, v_copy);
+        }
+
+        {
+            let v_iter_reversed = v_iter.iter().cloned().rev();
+            let v_reversed = VariantArray::from_iter(v_iter_reversed);
+
+            assert_ne!(v, v_reversed);
+        }
+
+        {
+            let v_sliced = v.slice(0, 1);
+            assert_ne!(v, v_sliced);
+        }
+    }
 }

Reply via email to