diff --git a/parquet-variant/src/variant/list.rs b/parquet-variant/src/variant/list.rs index 6de6ed830720..ca15932347c0 100644 --- a/parquet-variant/src/variant/list.rs +++ b/parquet-variant/src/variant/list.rs @@ -117,7 +117,7 @@ impl VariantListHeader { /// /// [valid]: VariantMetadata#Validation /// [Variant spec]: https://github.com/apache/parquet-format/blob/master/VariantEncoding.md#value-data-for-array-basic_type3 -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone)] pub struct VariantList<'m, 'v> { pub metadata: VariantMetadata<'m>, pub value: &'v [u8], @@ -302,6 +302,16 @@ impl<'m, 'v> VariantList<'m, 'v> { } } +impl<'m, 'v> PartialEq for VariantList<'m, 'v> { + fn eq(&self, other: &Self) -> bool { + self.metadata == other.metadata + && self.value == other.value + && self.header == other.header + && self.num_elements == other.num_elements + && self.first_value_byte == other.first_value_byte + } +} + #[cfg(test)] mod tests { use super::*; @@ -627,4 +637,24 @@ mod tests { assert_eq!(expected_list.get(i).unwrap(), item_str); } } + + #[test] + fn items_are_equal_even_if_not_validated() { + use crate::Variant; + use crate::VariantBuilder; + + let mut builder = VariantBuilder::new(); + + let mut list = builder.new_list(); + list.append_value("hello2"); + list.finish(); + + let (metadata, value) = builder.finish(); + + let variant1 = Variant::new(&metadata, &value); + let variant2 = Variant::new(&metadata, &value) + .with_full_validation() + .unwrap(); + assert_eq!(variant1, variant2) + } } diff --git a/parquet-variant/src/variant/metadata.rs b/parquet-variant/src/variant/metadata.rs index f957ebb6f15b..6ae9eb8dbd2d 100644 --- a/parquet-variant/src/variant/metadata.rs +++ b/parquet-variant/src/variant/metadata.rs @@ -355,10 +355,8 @@ impl<'m> VariantMetadata<'m> { // checks whether the dictionary entries are equal -- regardless of their sorting order impl<'m> PartialEq for VariantMetadata<'m> { fn eq(&self, other: &Self) -> bool { - let is_equal = self.is_empty() == other.is_empty() - && self.is_fully_validated() == other.is_fully_validated() - && self.first_value_byte == other.first_value_byte - && self.validated == other.validated; + let is_equal = + self.is_empty() == other.is_empty() && self.first_value_byte == other.first_value_byte; let other_field_names: HashSet<&'m str> = HashSet::from_iter(other.iter()); @@ -531,4 +529,15 @@ mod tests { "unexpected error: {err:?}" ); } + + #[test] + fn metadata_is_equal() { + let metadata_bytes = vec![0x11, 0, 0]; + let metadata1 = VariantMetadata::try_new(&metadata_bytes).unwrap(); + let metadata2 = VariantMetadata::try_new(&metadata_bytes) + .unwrap() + .with_full_validation() + .unwrap(); + assert_eq!(metadata1, metadata2) + } } diff --git a/parquet-variant/src/variant/object.rs b/parquet-variant/src/variant/object.rs index bce2ffc876b5..d8292f5e007b 100644 --- a/parquet-variant/src/variant/object.rs +++ b/parquet-variant/src/variant/object.rs @@ -416,8 +416,7 @@ impl<'m, 'v> PartialEq for VariantObject<'m, 'v> { && self.header == other.header && self.num_elements == other.num_elements && self.first_field_offset_byte == other.first_field_offset_byte - && self.first_value_byte == other.first_value_byte - && self.validated == other.validated; + && self.first_value_byte == other.first_value_byte; // value validation let other_fields: HashMap<&str, Variant> = HashMap::from_iter(other.iter()); @@ -949,4 +948,25 @@ mod tests { // objects are still logically equal assert_eq!(v1, v2); } + + #[test] + fn items_are_equal_even_if_not_validated() { + use crate::Variant; + use crate::VariantBuilder; + + let mut builder = VariantBuilder::new(); + let mut obj = builder.new_object(); + obj.insert("field1", "hello"); + obj.insert("field2", 34); + obj.insert("field3", true); + obj.finish().unwrap(); + + let (metadata, value) = builder.finish(); + + let variant1 = Variant::new(&metadata, &value); + let variant2 = Variant::new(&metadata, &value) + .with_full_validation() + .unwrap(); + assert_eq!(variant1, variant2) + } }