15
15
// specific language governing permissions and limitations
16
16
// under the License.
17
17
18
- use std:: collections:: HashSet ;
19
-
20
18
use crate :: decoder:: { map_bytes_to_offsets, OffsetSizeBytes } ;
21
19
use crate :: utils:: { first_byte_from_slice, overflow_error, slice_from_slice, string_from_slice} ;
22
20
@@ -127,7 +125,7 @@ impl VariantMetadataHeader {
127
125
///
128
126
/// [`Variant`]: crate::Variant
129
127
/// [Variant Spec]: https://github.com/apache/parquet-format/blob/master/VariantEncoding.md#metadata-encoding
130
- #[ derive( Debug , Clone ) ]
128
+ #[ derive( Debug , Clone , PartialEq ) ]
131
129
pub struct VariantMetadata < ' m > {
132
130
pub ( crate ) bytes : & ' m [ u8 ] ,
133
131
header : VariantMetadataHeader ,
@@ -335,23 +333,6 @@ impl<'m> VariantMetadata<'m> {
335
333
}
336
334
}
337
335
338
- // Metadata dictionaries can be in any order per the spec to allow flexible Variant construction
339
- // This comparison checks for field name presence in both metadata instances rather than raw byte equality
340
- impl < ' m > PartialEq for VariantMetadata < ' m > {
341
- fn eq ( & self , other : & Self ) -> bool {
342
- self . is_empty ( ) == other. is_empty ( )
343
- && if self . is_sorted ( ) && other. is_sorted ( ) {
344
- self . len ( ) == other. len ( ) && self . iter ( ) . eq ( other. iter ( ) )
345
- } else {
346
- // can't guarantee neither field names are unique
347
- let self_field_names: HashSet < & ' m str > = HashSet :: from_iter ( self . iter ( ) ) ;
348
- let other_field_names: HashSet < & ' m str > = HashSet :: from_iter ( other. iter ( ) ) ;
349
-
350
- self_field_names == other_field_names
351
- }
352
- }
353
- }
354
-
355
336
/// Retrieves the ith dictionary entry, panicking if the index is out of bounds. Accessing
356
337
/// [unvalidated] input could also panic if the underlying bytes are invalid.
357
338
///
@@ -586,42 +567,7 @@ mod tests {
586
567
let m2 = VariantMetadata :: try_new ( & metadata_bytes) . unwrap ( ) ;
587
568
assert ! ( !m2. is_sorted( ) ) ;
588
569
589
- assert_eq ! ( m1, m2) ;
590
- }
591
-
592
- #[ test]
593
- fn test_compare_sorted_dictionary_with_unsorted_dictionary2 ( ) {
594
- // create a sorted object
595
- let mut b = VariantBuilder :: new ( ) ;
596
- let mut o = b. new_object ( ) ;
597
-
598
- o. insert ( "a" , false ) ;
599
- o. insert ( "b" , false ) ;
600
-
601
- o. finish ( ) . unwrap ( ) ;
602
-
603
- let ( m, _) = b. finish ( ) ;
604
-
605
- let m1 = VariantMetadata :: new ( & m) ;
606
- assert ! ( m1. is_sorted( ) ) ;
607
-
608
- // Create metadata with an unsorted dictionary (field names are "b", "b", "a")
609
- // Since field names are not unique nor lexicographically ordered, it is considered not sorted.
610
- let metadata_bytes = vec ! [
611
- 0b0000_0001 ,
612
- 3 , // dictionary size
613
- 0 , // "b"
614
- 1 , // "b"
615
- 2 , // "a"
616
- 3 ,
617
- b'b' ,
618
- b'b' ,
619
- b'a' ,
620
- ] ;
621
- let m2 = VariantMetadata :: try_new ( & metadata_bytes) . unwrap ( ) ;
622
- assert ! ( !m2. is_sorted( ) ) ;
623
-
624
- assert_eq ! ( m1, m2) ;
570
+ assert_ne ! ( m1, m2) ;
625
571
}
626
572
627
573
#[ test]
@@ -642,35 +588,4 @@ mod tests {
642
588
643
589
assert_eq ! ( m1, m2) ;
644
590
}
645
-
646
- #[ test]
647
- fn test_compare_sorted_dictionary_with_sorted_dictionary2 ( ) {
648
- // create a sorted object
649
- let mut b = VariantBuilder :: new ( ) ;
650
- let mut o = b. new_object ( ) ;
651
-
652
- o. insert ( "a" , false ) ;
653
- o. insert ( "b" , false ) ;
654
-
655
- o. finish ( ) . unwrap ( ) ;
656
-
657
- let ( m, _) = b. finish ( ) ;
658
-
659
- let m1 = VariantMetadata :: new ( & m) ;
660
-
661
- // create a sorted object with different field names
662
- let mut b = VariantBuilder :: new ( ) ;
663
- let mut o = b. new_object ( ) ;
664
-
665
- o. insert ( "c" , false ) ;
666
- o. insert ( "d" , false ) ;
667
-
668
- o. finish ( ) . unwrap ( ) ;
669
-
670
- let ( m, _) = b. finish ( ) ;
671
-
672
- let m2 = VariantMetadata :: new ( & m) ;
673
-
674
- assert_ne ! ( m1, m2) ;
675
- }
676
591
}
0 commit comments