alamb commented on code in PR #7943: URL: https://github.com/apache/arrow-rs/pull/7943#discussion_r2213281991
########## parquet-variant/src/variant/object.rs: ########## @@ -718,4 +752,187 @@ mod tests { test_variant_object_with_large_data(16777216 + 1, OffsetSizeBytes::Four); // 2^24 } + + #[test] + fn test_objects_with_same_fields_are_equal() { + let mut b = VariantBuilder::new(); + let mut o = b.new_object(); + + o.insert("b", ()); + o.insert("c", ()); + o.insert("a", ()); + + o.finish().unwrap(); + + let (m, v) = b.finish(); + + let v1 = Variant::try_new(&m, &v).unwrap(); + let v2 = Variant::try_new(&m, &v).unwrap(); + + assert_eq!(v1, v2); + } + + #[test] + fn test_same_objects_with_different_builder_are_equal() { + let mut b = VariantBuilder::new(); + let mut o = b.new_object(); + + o.insert("a", ()); + o.insert("b", false); + + o.finish().unwrap(); + let (m, v) = b.finish(); + + let v1 = Variant::try_new(&m, &v).unwrap(); + + let mut b = VariantBuilder::new(); + let mut o = b.new_object(); + + o.insert("a", ()); + o.insert("b", false); + + o.finish().unwrap(); + let (m, v) = b.finish(); + + let v2 = Variant::try_new(&m, &v).unwrap(); + + assert_eq!(v1, v2); + } + + #[test] + fn test_objects_with_different_values_are_not_equal() { + let mut b = VariantBuilder::new(); + let mut o = b.new_object(); + + o.insert("a", ()); + o.insert("b", 4.3); + + o.finish().unwrap(); + + let (m, v) = b.finish(); + + let v1 = Variant::try_new(&m, &v).unwrap(); + + // second object, same field name but different values + let mut b = VariantBuilder::new(); + let mut o = b.new_object(); + + o.insert("a", ()); + let mut inner_o = o.new_object("b"); + inner_o.insert("a", 3.3); + inner_o.finish().unwrap(); + o.finish().unwrap(); + + let (m, v) = b.finish(); + + let v2 = Variant::try_new(&m, &v).unwrap(); + + let m1 = v1.metadata().unwrap(); + let m2 = v2.metadata().unwrap(); + + // metadata would be equal since they contain the same keys + assert_eq!(m1, m2); + + // but the objects are not equal + assert_ne!(v1, v2); + } + + #[test] + fn test_objects_with_different_field_names_are_not_equal() { + let mut b = VariantBuilder::new(); + let mut o = b.new_object(); + + o.insert("a", ()); + o.insert("b", 4.3); + + o.finish().unwrap(); + + let (m, v) = b.finish(); + + let v1 = Variant::try_new(&m, &v).unwrap(); + + // second object, same field name but different values + let mut b = VariantBuilder::new(); + let mut o = b.new_object(); + + o.insert("aardvark", ()); + o.insert("barracuda", 3.3); + + o.finish().unwrap(); + + let (m, v) = b.finish(); + let v2 = Variant::try_new(&m, &v).unwrap(); + + assert_ne!(v1, v2); + } + + #[test] + fn test_objects_with_different_insertion_order_are_equal() { + let mut b = VariantBuilder::new(); + let mut o = b.new_object(); + + o.insert("b", false); + o.insert("a", ()); + + o.finish().unwrap(); + + let (m, v) = b.finish(); + + let v1 = Variant::try_new(&m, &v).unwrap(); + assert!(!v1.metadata().unwrap().is_sorted()); + + // create another object pre-filled with field names, b and a + // but insert the fields in the order of a, b + let mut b = VariantBuilder::new().with_field_names(["b", "a"].into_iter()); + let mut o = b.new_object(); + + o.insert("a", ()); + o.insert("b", false); + + o.finish().unwrap(); + + let (m, v) = b.finish(); + + let v2 = Variant::try_new(&m, &v).unwrap(); + + // v2 should also have a unsorted dictionary + assert!(!v2.metadata().unwrap().is_sorted()); + + assert_eq!(v1, v2); + } + + #[test] + fn test_objects_with_differing_metadata_are_equal() { Review Comment: For a follow on work, I think we should -- 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