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.
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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With