@@ -1077,18 +1077,40 @@ mod tests {
1077
1077
1078
1078
#[ test]
1079
1079
fn test_byte_view_take_n ( ) {
1080
+ // `take_n` is really complex, we should consider and test following situations:
1081
+ // 1. Take all `inlined`s
1082
+ // 2. Take non-inlined + partial last buffer in `completed`
1083
+ // 3. Take non-inlined + whole last buffer in `completed`
1084
+ // 4. Take non-inlined + partial last `in_progress`
1085
+ // 5. Take non-inlined + while last buffer in ``in_progress`
1086
+ // 6. Take all views at once
1087
+
1080
1088
let mut builder =
1081
1089
ByteViewGroupValueBuilder :: < StringViewType > :: new ( ) . with_max_block_size ( 60 ) ;
1082
1090
let input_array = StringViewArray :: from ( vec ! [
1083
- Some ( "this string is quite long" ) , // in buffer 0
1091
+ // Test situation 1 (also test take null together)
1092
+ None ,
1084
1093
Some ( "foo" ) ,
1085
1094
Some ( "bar" ) ,
1086
- Some ( "this string is also quite long" ) , // buffer 0
1095
+ // Test situation 2 ( also test take null + inlined)
1087
1096
None ,
1088
- Some ( "this string is quite long" ) , // buffer 1
1097
+ Some ( "foo" ) ,
1098
+ Some ( "this string is quite long" ) ,
1099
+ Some ( "this string is also quite long" ) ,
1100
+ // Test situation 3 (also test take null + inlined)
1089
1101
None ,
1090
- Some ( "another string that is is quite long" ) , // buffer 1
1091
1102
Some ( "bar" ) ,
1103
+ Some ( "this string is quite long" ) ,
1104
+ // Test situation 4 (also test take null + inlined)
1105
+ None ,
1106
+ Some ( "foo" ) ,
1107
+ Some ( "another string that is is quite long" ) ,
1108
+ Some ( "this string not so long" ) ,
1109
+ // Test situation 5 (also test take null + inlined + insert again after taking)
1110
+ None ,
1111
+ Some ( "bar" ) ,
1112
+ Some ( "this string is quite long" ) ,
1113
+ // Finally, we insert the whole array again for testing situation 6
1092
1114
] ) ;
1093
1115
let input_array: ArrayRef = Arc :: new ( input_array) ;
1094
1116
for row in 0 ..input_array. len ( ) {
@@ -1097,45 +1119,71 @@ mod tests {
1097
1119
1098
1120
// should be 2 completed, one in progress buffer to hold all output
1099
1121
assert_eq ! ( builder. completed. len( ) , 2 ) ;
1122
+ println ! ( "{}" , builder. in_progress. len( ) ) ;
1100
1123
assert ! ( !builder. in_progress. is_empty( ) ) ;
1101
1124
1102
- let first_4 = builder. take_n ( 4 ) ;
1125
+ // Take all `inlined`s
1126
+ let taken_array = builder. take_n ( 2 ) ;
1103
1127
println ! (
1104
1128
"{}" ,
1105
1129
arrow:: util:: pretty:: pretty_format_columns(
1106
- "first_4 " ,
1107
- & [ Arc :: clone( & first_4 ) ]
1130
+ "taken_array " ,
1131
+ & [ Arc :: clone( & taken_array ) ]
1108
1132
)
1109
1133
. unwrap( )
1110
1134
) ;
1111
- assert_eq ! ( & first_4 , & input_array. slice( 0 , 4 ) ) ;
1135
+ assert_eq ! ( & taken_array , & input_array. slice( 0 , 2 ) ) ;
1112
1136
1113
- // Add some new data after the first n
1114
- let input_array = StringViewArray :: from ( vec ! [
1115
- Some ( "short" ) ,
1116
- None ,
1117
- Some ( "Some new data to add that is long" ) , // in buffer 0
1118
- Some ( "short again" ) ,
1119
- ] ) ;
1120
- let input_array : ArrayRef = Arc :: new ( input_array ) ;
1121
- for row in 0 ..input_array . len ( ) {
1122
- builder . append_val ( & input_array , row ) ;
1123
- }
1137
+ // Take non-inlined + partial buffer 0
1138
+ let taken_array = builder . take_n ( 1 ) ;
1139
+ println ! (
1140
+ "{}" ,
1141
+ arrow :: util :: pretty :: pretty_format_columns (
1142
+ "taken_array" ,
1143
+ & [ Arc :: clone ( & taken_array ) ]
1144
+ )
1145
+ . unwrap ( )
1146
+ ) ;
1147
+ assert_eq ! ( & taken_array , & input_array . slice ( 2 , 1 ) ) ;
1124
1148
1125
- let result = Box :: new ( builder) . build ( ) ;
1126
- let expected: ArrayRef = Arc :: new ( StringViewArray :: from ( vec ! [
1127
- // last rows of the original input
1128
- None ,
1129
- Some ( "this string is quite long" ) ,
1130
- None ,
1131
- Some ( "another string that is is quite long" ) ,
1132
- Some ( "bar" ) ,
1133
- // the subsequent input
1134
- Some ( "short" ) ,
1135
- None ,
1136
- Some ( "Some new data to add that is long" ) , // in buffer 0
1137
- Some ( "short again" ) ,
1138
- ] ) ) ;
1139
- assert_eq ! ( & result, & expected) ;
1149
+ // Take non-inlined + remaining partial buffer 0
1150
+ let taken_array = builder. take_n ( 1 ) ;
1151
+ println ! (
1152
+ "{}" ,
1153
+ arrow:: util:: pretty:: pretty_format_columns(
1154
+ "taken_array" ,
1155
+ & [ Arc :: clone( & taken_array) ]
1156
+ )
1157
+ . unwrap( )
1158
+ ) ;
1159
+ assert_eq ! ( & taken_array, & input_array. slice( 3 , 1 ) ) ;
1160
+
1161
+ // Add some new data after the first n
1162
+ // let input_array = StringViewArray::from(vec![
1163
+ // Some("short"),
1164
+ // None,
1165
+ // Some("Some new data to add that is long"), // in buffer 0
1166
+ // Some("short again"),
1167
+ // ]);
1168
+ // let input_array: ArrayRef = Arc::new(input_array);
1169
+ // for row in 0..input_array.len() {
1170
+ // builder.append_val(&input_array, row);
1171
+ // }
1172
+
1173
+ // let result = Box::new(builder).build();
1174
+ // let expected: ArrayRef = Arc::new(StringViewArray::from(vec![
1175
+ // // last rows of the original input
1176
+ // None,
1177
+ // Some("this string is quite long"),
1178
+ // None,
1179
+ // Some("another string that is is quite long"),
1180
+ // Some("bar"),
1181
+ // // the subsequent input
1182
+ // Some("short"),
1183
+ // None,
1184
+ // Some("Some new data to add that is long"), // in buffer 0
1185
+ // Some("short again"),
1186
+ // ]));
1187
+ // assert_eq!(&result, &expected);
1140
1188
}
1141
1189
}
0 commit comments