Skip to content

Commit a85d8b0

Browse files
[Variant] impl PartialEq and FromIterator<Option<..>> for VariantArray (#8627)
# Which issue does this PR close? - Closes #8610 # Rationale for this change Since the fields of `VariantArray` impl `PartialEq`, this PR simply derives `PartialEq` for `VariantArray` out. Based off of #8625
1 parent 2ca3d60 commit a85d8b0

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

parquet-variant-compute/src/variant_array.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl ExtensionType for VariantType {
208208
/// assert_eq!(variant_array.value(0), Variant::from("such wow"));
209209
/// ```
210210
///
211-
#[derive(Clone, Debug)]
211+
#[derive(Debug, Clone, PartialEq)]
212212
pub struct VariantArray {
213213
/// Reference to the underlying StructArray
214214
inner: StructArray,
@@ -741,7 +741,7 @@ impl From<ShreddedVariantFieldArray> for StructArray {
741741
/// (partial shredding).
742742
///
743743
/// [Parquet Variant Shredding Spec]: https://github.com/apache/parquet-format/blob/master/VariantShredding.md#value-shredding
744-
#[derive(Clone, Debug)]
744+
#[derive(Debug, Clone, PartialEq)]
745745
pub struct ShreddingState {
746746
value: Option<BinaryViewArray>,
747747
typed_value: Option<ArrayRef>,
@@ -1467,4 +1467,27 @@ mod test {
14671467
Variant::ShortString(ShortString::try_new("norm").unwrap())
14681468
);
14691469
}
1470+
1471+
#[test]
1472+
fn test_variant_equality() {
1473+
let v_iter = [None, Some(Variant::BooleanFalse), Some(Variant::Null), None];
1474+
let v = VariantArray::from_iter(v_iter.clone());
1475+
1476+
{
1477+
let v_copy = v.clone();
1478+
assert_eq!(v, v_copy);
1479+
}
1480+
1481+
{
1482+
let v_iter_reversed = v_iter.iter().cloned().rev();
1483+
let v_reversed = VariantArray::from_iter(v_iter_reversed);
1484+
1485+
assert_ne!(v, v_reversed);
1486+
}
1487+
1488+
{
1489+
let v_sliced = v.slice(0, 1);
1490+
assert_ne!(v, v_sliced);
1491+
}
1492+
}
14701493
}

0 commit comments

Comments
 (0)