@@ -594,8 +594,6 @@ impl From<Vec<Option<String>>> for StringViewArray {
594
594
595
595
/// A helper struct that used to check if the array is compact view
596
596
///
597
- /// # Note
598
- ///
599
597
/// The checker is lazy and will not check the array until `finish` is called.
600
598
///
601
599
/// This is based on the assumption that the array will most likely to be not compact,
@@ -635,7 +633,7 @@ impl CompactChecker {
635
633
pub fn finish ( self ) -> bool {
636
634
// check if the coverage is continuous and full
637
635
let mut last_end = 0 ;
638
- // todo: can be optimized
636
+
639
637
for ( start, end) in self . intervals . iter ( ) {
640
638
if * start > last_end {
641
639
return false ;
@@ -814,14 +812,17 @@ mod tests {
814
812
#[ test]
815
813
fn test_compact_checker ( ) {
816
814
use super :: CompactChecker ;
815
+
817
816
// single coverage, full
818
817
let mut checker = CompactChecker :: new ( 10 ) ;
819
818
checker. accumulate ( 0 , 10 ) ;
820
819
assert ! ( checker. finish( ) ) ;
820
+
821
821
// single coverage, partial
822
822
let mut checker = CompactChecker :: new ( 10 ) ;
823
823
checker. accumulate ( 0 , 5 ) ;
824
824
assert ! ( !checker. finish( ) ) ;
825
+
825
826
// multiple coverage, no overlapping, partial
826
827
let mut checker = CompactChecker :: new ( 10 ) ;
827
828
checker. accumulate ( 0 , 5 ) ;
@@ -833,6 +834,7 @@ mod tests {
833
834
checker. accumulate ( 0 , 5 ) ;
834
835
checker. accumulate ( 5 , 5 ) ;
835
836
assert ! ( checker. finish( ) ) ;
837
+
836
838
//multiple coverage, overlapping, partial
837
839
let mut checker = CompactChecker :: new ( 10 ) ;
838
840
checker. accumulate ( 0 , 5 ) ;
@@ -844,6 +846,7 @@ mod tests {
844
846
checker. accumulate ( 0 , 5 ) ;
845
847
checker. accumulate ( 4 , 6 ) ;
846
848
assert ! ( checker. finish( ) ) ;
849
+
847
850
//mutiple coverage, no overlapping, full, out of order
848
851
let mut checker = CompactChecker :: new ( 10 ) ;
849
852
checker. accumulate ( 4 , 6 ) ;
@@ -862,42 +865,57 @@ mod tests {
862
865
checker. accumulate ( 5 , 0 ) ;
863
866
checker. accumulate ( 5 , 5 ) ;
864
867
assert ! ( checker. finish( ) ) ;
868
+
865
869
// multiple coverage, overlapping, full, containing null
866
870
let mut checker = CompactChecker :: new ( 10 ) ;
867
871
checker. accumulate ( 0 , 5 ) ;
868
872
checker. accumulate ( 5 , 0 ) ;
869
873
checker. accumulate ( 4 , 6 ) ;
870
874
checker. accumulate ( 5 , 5 ) ;
871
875
assert ! ( checker. finish( ) ) ;
876
+
877
+ // multiple coverage, overlapping, full, containing null
878
+ //
879
+ // this case is for attacking those implementation that only check
880
+ // the lower-bound of the interval
881
+ let mut checker = CompactChecker :: new ( 10 ) ;
882
+ checker. accumulate ( 0 , 5 ) ;
883
+ checker. accumulate ( 5 , 0 ) ;
884
+ checker. accumulate ( 1 , 9 ) ;
885
+ checker. accumulate ( 2 , 3 ) ;
886
+ checker. accumulate ( 3 , 1 ) ;
887
+ checker. accumulate ( 9 , 2 ) ;
888
+ assert ! ( checker. finish( ) )
872
889
}
873
890
874
891
#[ test]
875
892
fn test_gc ( ) {
893
+ // ---------------------------------------------------------------------
876
894
// test compact on compacted data
895
+
877
896
let array = {
878
897
let mut builder = StringViewBuilder :: new ( ) ;
879
898
builder. append_value ( "I look at you all" ) ;
880
899
builder. append_option ( Some ( "see the love there that's sleeping" ) ) ;
881
900
builder. finish ( )
882
901
} ;
883
-
884
902
let compacted = array. gc ( ) ;
885
903
// verify it is a shallow copy
886
904
assert_eq ! ( array. buffers[ 0 ] . as_ptr( ) , compacted. buffers[ 0 ] . as_ptr( ) ) ;
887
905
906
+ // ---------------------------------------------------------------------
888
907
// test compact on non-compacted data
908
+
889
909
let mut array = {
890
910
let mut builder = StringViewBuilder :: new ( ) ;
891
911
builder. append_value ( "while my guitar gently weeps" ) ;
892
912
builder. finish ( )
893
913
} ;
894
-
895
914
// shrink the view
896
915
let mut view = ByteView :: from ( array. views [ 0 ] ) ;
897
916
view. length = 15 ;
898
917
let new_views = ScalarBuffer :: from ( vec ! [ view. into( ) ] ) ;
899
918
array. views = new_views;
900
-
901
919
let compacted = array. gc ( ) ;
902
920
// verify it is a deep copy
903
921
assert_ne ! ( array. buffers[ 0 ] . as_ptr( ) , compacted. buffers[ 0 ] . as_ptr( ) ) ;
@@ -906,7 +924,9 @@ mod tests {
906
924
// verify compacted
907
925
assert ! ( compacted. compact_check( ) . iter( ) . all( |x| * x) ) ;
908
926
927
+ // ---------------------------------------------------------------------
909
928
// test compact on array containing null
929
+
910
930
let mut array = {
911
931
let mut builder = StringViewBuilder :: new ( ) ;
912
932
builder. append_null ( ) ;
@@ -926,7 +946,9 @@ mod tests {
926
946
assert_eq ! ( array. value( 1 ) , compacted. value( 1 ) ) ;
927
947
assert ! ( compacted. compact_check( ) . iter( ) . all( |x| * x) ) ;
928
948
949
+ // ---------------------------------------------------------------------
929
950
// test compact on multiple buffers
951
+
930
952
let mut array = {
931
953
let mut builder = StringViewBuilder :: new ( ) . with_block_size ( 15 ) ;
932
954
builder. append_value ( "how to unfold your love" ) ;
0 commit comments