50
50
import org .apache .hadoop .hbase .filter .Filter ;
51
51
import org .apache .hadoop .hbase .filter .FilterList ;
52
52
import org .apache .hadoop .hbase .filter .FirstKeyOnlyFilter ;
53
+ import org .apache .hadoop .hbase .filter .FuzzyRowFilter ;
53
54
import org .apache .hadoop .hbase .filter .InclusiveStopFilter ;
54
55
import org .apache .hadoop .hbase .filter .KeyOnlyFilter ;
55
56
import org .apache .hadoop .hbase .filter .MultiRowRangeFilter ;
75
76
import org .apache .hadoop .hbase .security .visibility .Authorizations ;
76
77
import org .apache .hadoop .hbase .util .ByteStringer ;
77
78
import org .apache .hadoop .hbase .util .Bytes ;
79
+ import org .apache .hadoop .hbase .util .Pair ;
78
80
import org .apache .yetus .audience .InterfaceAudience ;
79
81
80
82
import org .apache .hbase .thirdparty .com .fasterxml .jackson .jaxrs .json .JacksonJaxbJsonProvider ;
@@ -277,6 +279,63 @@ public boolean equals(Object obj) {
277
279
278
280
}
279
281
282
+ static class FuzzyKeyModel {
283
+
284
+ protected byte [] key ;
285
+
286
+ protected byte [] mask ;
287
+
288
+ public FuzzyKeyModel () {
289
+ }
290
+
291
+ public FuzzyKeyModel (Pair <byte [], byte []> keyWithMask ) {
292
+ this .key = keyWithMask .getFirst ();
293
+ this .mask = keyWithMask .getSecond ();
294
+ }
295
+
296
+ public Pair <byte [], byte []> build () {
297
+ return new Pair <>(key , mask );
298
+ }
299
+
300
+ public byte [] getKey () {
301
+ return key ;
302
+ }
303
+
304
+ public void setKey (byte [] key ) {
305
+ this .key = key ;
306
+ }
307
+
308
+ public byte [] getMask () {
309
+ return mask ;
310
+ }
311
+
312
+ public void setMask (byte [] mask ) {
313
+ this .mask = mask ;
314
+ }
315
+
316
+ @ Override
317
+ public int hashCode () {
318
+ final int prime = 31 ;
319
+ int result = 1 ;
320
+ result = prime * result + Arrays .hashCode (key );
321
+ result = prime * result + Arrays .hashCode (mask );
322
+ return result ;
323
+ }
324
+
325
+ @ Override
326
+ public boolean equals (Object obj ) {
327
+ if (this == obj ) {
328
+ return true ;
329
+ }
330
+ if (!(obj instanceof FuzzyKeyModel )) {
331
+ return false ;
332
+ }
333
+ FuzzyKeyModel other = (FuzzyKeyModel ) obj ;
334
+ return Arrays .equals (key , other .key ) && Arrays .equals (mask , other .mask );
335
+ }
336
+
337
+ }
338
+
280
339
// A grab bag of fields, would have been a union if this were C.
281
340
// These are null by default and will only be serialized if set (non null).
282
341
@ XmlAttribute
@@ -319,6 +378,8 @@ public boolean equals(Object obj) {
319
378
private List <RowRangeModel > ranges ;
320
379
@ XmlElement
321
380
public List <Long > timestamps ;
381
+ @ XmlElement
382
+ private List <FuzzyKeyModel > fuzzyKeys ;
322
383
323
384
static enum FilterType {
324
385
ColumnCountGetFilter ,
@@ -343,7 +404,8 @@ static enum FilterType {
343
404
SkipFilter ,
344
405
TimestampsFilter ,
345
406
ValueFilter ,
346
- WhileMatchFilter
407
+ WhileMatchFilter ,
408
+ FuzzyRowFilter
347
409
}
348
410
349
411
public FilterModel () {
@@ -456,6 +518,12 @@ public FilterModel(Filter filter) {
456
518
this .filters = new ArrayList <>();
457
519
this .filters .add (new FilterModel (((WhileMatchFilter ) filter ).getFilter ()));
458
520
break ;
521
+ case FuzzyRowFilter :
522
+ this .fuzzyKeys = new ArrayList <>();
523
+ for (Pair <byte [], byte []> keyWithMask : ((FuzzyRowFilter ) filter ).getFuzzyKeys ()) {
524
+ this .fuzzyKeys .add (new FuzzyKeyModel (keyWithMask ));
525
+ }
526
+ break ;
459
527
default :
460
528
throw new RuntimeException ("unhandled filter type " + type );
461
529
}
@@ -567,6 +635,14 @@ public Filter build() {
567
635
case WhileMatchFilter :
568
636
filter = new WhileMatchFilter (filters .get (0 ).build ());
569
637
break ;
638
+ case FuzzyRowFilter : {
639
+ ArrayList <Pair <byte [], byte []>> fuzzyKeyArgs = new ArrayList <>(fuzzyKeys .size ());
640
+ for (FuzzyKeyModel keyModel : fuzzyKeys ) {
641
+ fuzzyKeyArgs .add (keyModel .build ());
642
+ }
643
+ filter = new FuzzyRowFilter (fuzzyKeyArgs );
644
+ }
645
+ break ;
570
646
default :
571
647
throw new RuntimeException ("unhandled filter type: " + type );
572
648
}
0 commit comments