18
18
package org .apache .hadoop .hbase .filter ;
19
19
20
20
import static org .junit .Assert .assertEquals ;
21
-
22
21
import java .io .IOException ;
23
22
import java .nio .ByteBuffer ;
24
23
import java .util .ArrayList ;
56
55
import org .junit .rules .TestName ;
57
56
import org .slf4j .Logger ;
58
57
import org .slf4j .LoggerFactory ;
59
-
60
58
import org .apache .hbase .thirdparty .com .google .common .collect .Lists ;
61
59
62
60
@ Category ({ FilterTests .class , LargeTests .class })
@@ -142,7 +140,16 @@ public void testAllFixedBits() throws IOException {
142
140
143
141
TEST_UTIL .flush ();
144
142
145
- List <Pair <byte [], byte []>> data = new ArrayList <>();
143
+ // v1 should match all rows, because v2 has the actual fix for this bug
144
+ testAllFixedBitsRunScanWithMask (ht , rows .length , FuzzyRowFilter .V1_PROCESSED_WILDCARD_MASK );
145
+ testAllFixedBitsRunScanWithMask (ht , 2 , FuzzyRowFilter .V2_PROCESSED_WILDCARD_MASK );
146
+
147
+ TEST_UTIL .deleteTable (TableName .valueOf (table ));
148
+ }
149
+
150
+ private void testAllFixedBitsRunScanWithMask (Table ht , int expectedRows , byte processedRowMask )
151
+ throws IOException {
152
+ List <Pair <byte [], byte []>> data = new ArrayList <Pair <byte [], byte []>>();
146
153
byte [] fuzzyKey = Bytes .toBytesBinary ("\\ x9B\\ x00\\ x044e" );
147
154
byte [] mask = new byte [] { 0 , 0 , 0 , 0 , 0 };
148
155
@@ -151,7 +158,7 @@ public void testAllFixedBits() throws IOException {
151
158
byte [] copyMask = Arrays .copyOf (mask , mask .length );
152
159
153
160
data .add (new Pair <>(fuzzyKey , mask ));
154
- FuzzyRowFilter filter = new FuzzyRowFilter (data );
161
+ FuzzyRowFilter filter = new FuzzyRowFilter (data , processedRowMask );
155
162
156
163
Scan scan = new Scan ();
157
164
scan .setFilter (filter );
@@ -161,12 +168,10 @@ public void testAllFixedBits() throws IOException {
161
168
while (scanner .next () != null ) {
162
169
total ++;
163
170
}
164
- assertEquals (2 , total );
171
+ assertEquals (expectedRows , total );
165
172
166
173
assertEquals (true , Arrays .equals (copyFuzzyKey , fuzzyKey ));
167
174
assertEquals (true , Arrays .equals (copyMask , mask ));
168
-
169
- TEST_UTIL .deleteTable (TableName .valueOf (name .getMethodName ()));
170
175
}
171
176
172
177
@ Test
@@ -201,11 +206,20 @@ public void testHBASE14782() throws IOException
201
206
202
207
TEST_UTIL .flush ();
203
208
204
- List <Pair <byte [], byte []>> data = new ArrayList <>();
209
+ testHBASE14782RunScanWithMask (ht , rows .length , FuzzyRowFilter .V1_PROCESSED_WILDCARD_MASK );
210
+ testHBASE14782RunScanWithMask (ht , rows .length , FuzzyRowFilter .V2_PROCESSED_WILDCARD_MASK );
211
+
212
+ TEST_UTIL .deleteTable (TableName .valueOf (name .getMethodName ()));
213
+ }
214
+
215
+ private void testHBASE14782RunScanWithMask (Table ht , int expectedRows , byte processedRowMask )
216
+ throws IOException {
217
+ List <Pair <byte [], byte []>> data = new ArrayList <Pair <byte [], byte []>>();
218
+
205
219
byte [] fuzzyKey = Bytes .toBytesBinary ("\\ x00\\ x00\\ x044" );
206
220
byte [] mask = new byte [] { 1 ,0 ,0 ,0 };
207
221
data .add (new Pair <>(fuzzyKey , mask ));
208
- FuzzyRowFilter filter = new FuzzyRowFilter (data );
222
+ FuzzyRowFilter filter = new FuzzyRowFilter (data , processedRowMask );
209
223
210
224
Scan scan = new Scan ();
211
225
scan .setFilter (filter );
@@ -215,8 +229,7 @@ public void testHBASE14782() throws IOException
215
229
while (scanner .next () != null ){
216
230
total ++;
217
231
}
218
- assertEquals (rows .length , total );
219
- TEST_UTIL .deleteTable (TableName .valueOf (name .getMethodName ()));
232
+ assertEquals (expectedRows , total );
220
233
}
221
234
222
235
@ Test
@@ -258,12 +271,14 @@ public void testEndToEnd() throws Exception {
258
271
TEST_UTIL .flush ();
259
272
260
273
// test passes
261
- runTest1 (ht );
262
- runTest2 (ht );
274
+ runTest1 (ht , FuzzyRowFilter .V1_PROCESSED_WILDCARD_MASK );
275
+ runTest1 (ht , FuzzyRowFilter .V2_PROCESSED_WILDCARD_MASK );
276
+ runTest2 (ht , FuzzyRowFilter .V1_PROCESSED_WILDCARD_MASK );
277
+ runTest2 (ht , FuzzyRowFilter .V2_PROCESSED_WILDCARD_MASK );
263
278
264
279
}
265
280
266
- private void runTest1 (Table hTable ) throws IOException {
281
+ private void runTest1 (Table hTable , byte processedWildcardMask ) throws IOException {
267
282
// [0, 2, ?, ?, ?, ?, 0, 0, 0, 1]
268
283
269
284
byte [] mask = new byte [] { 0 , 0 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 };
@@ -284,9 +299,9 @@ private void runTest1(Table hTable) throws IOException {
284
299
}
285
300
286
301
int expectedSize = secondPartCardinality * totalFuzzyKeys * colQualifiersTotal ;
287
- FuzzyRowFilter fuzzyRowFilter0 = new FuzzyRowFilter (list );
302
+ FuzzyRowFilter fuzzyRowFilter0 = new FuzzyRowFilter (list , processedWildcardMask );
288
303
// Filters are not stateless - we can't reuse them
289
- FuzzyRowFilter fuzzyRowFilter1 = new FuzzyRowFilter (list );
304
+ FuzzyRowFilter fuzzyRowFilter1 = new FuzzyRowFilter (list , processedWildcardMask );
290
305
291
306
// regular test
292
307
runScanner (hTable , expectedSize , fuzzyRowFilter0 );
@@ -295,7 +310,7 @@ private void runTest1(Table hTable) throws IOException {
295
310
296
311
}
297
312
298
- private void runTest2 (Table hTable ) throws IOException {
313
+ private void runTest2 (Table hTable , byte processedWildcardMask ) throws IOException {
299
314
// [0, 0, ?, ?, ?, ?, 0, 0, 0, 0] , [0, 1, ?, ?, ?, ?, 0, 0, 0, 1]...
300
315
301
316
byte [] mask = new byte [] { 0 , 0 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 };
@@ -318,9 +333,9 @@ private void runTest2(Table hTable) throws IOException {
318
333
319
334
int expectedSize = totalFuzzyKeys * secondPartCardinality * colQualifiersTotal ;
320
335
321
- FuzzyRowFilter fuzzyRowFilter0 = new FuzzyRowFilter (list );
336
+ FuzzyRowFilter fuzzyRowFilter0 = new FuzzyRowFilter (list , processedWildcardMask );
322
337
// Filters are not stateless - we can't reuse them
323
- FuzzyRowFilter fuzzyRowFilter1 = new FuzzyRowFilter (list );
338
+ FuzzyRowFilter fuzzyRowFilter1 = new FuzzyRowFilter (list , processedWildcardMask );
324
339
325
340
// regular test
326
341
runScanner (hTable , expectedSize , fuzzyRowFilter0 );
0 commit comments