Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HBase: How to specify multiple prefix filters in a single scan operation

I have got the scan result for a given partial row key using prefix filter:

Row key examples: 123_abc, 456_def, 789_ghi

var prefix=Bytes.toBytes("123")
var scan = new Scan(prefix)
var prefixFilter = new PrefixFilter(prefix)
scan.setFilter(prefixFilter)
var resultScanner = table.getScanner(scan)

Now, my question is how can I specify multiple prefix filters that will go as input for the scan operation. The Result object should contain all the rows that have row key value with the given prefix, say 123 or 456.

I have tried the following answer which uses FilterList approach but couldn't get the required result:

Set Multiple prefix row filter to scanner hbase java

Any help on this (in Scala or Java) would be greatly appreciated. Thank you.

like image 576
Arjun A J Avatar asked Dec 10 '16 09:12

Arjun A J


1 Answers

Please check this docs of filter list you might have NOT used correct option...

FilterList.Operator.MUST_PASS_ALL (AND) or FilterList.Operator.MUST_PASS_ONE (OR). Since you can use Filter Lists as children of Filter Lists, you can create a hierarchy of filters to be evaluated. FilterList.Operator.MUST_PASS_ALL evaluates lazily: evaluation stops as soon as one filter does not include the KeyValue. FilterList.Operator.MUST_PASS_ONE evaluates non-lazily: all filters are always evaluated. Defaults to FilterList.Operator.MUST_PASS_ALL.

 /* FilterList.Operator.MUST_PASS_ALL by default */
      FilterList allFilters = new FilterList(FilterList.Operator.MUST_PASS_ONE);
      allFilters.addFilter(new PrefixFilter(Bytes.toBytes("123")));
     allFilters.addFilter(new PrefixFilter(Bytes.toBytes("456")));
     allFilters.addFilter(new PrefixFilter(Bytes.toBytes("678")));
    scan.setFilter(allFilters);

    var resultScanner = table.getScanner(scan)

Point to verify :

since You already used FilterList, I think you might have used default one i.e MUST_PASS_ALL for which all prefix conditions needs to be met may be that's why its not giving result.

afore mentioned code should work.. Good luck

like image 89
Ram Ghadiyaram Avatar answered Sep 28 '22 07:09

Ram Ghadiyaram