Search code examples
javahbase

How do I mix MUST_PASS_ALL and MUST_PASS_ONE in HBase filters?


I have an HBase scan with a ColumnPrefixFilter and multiple FuzzyFilters like so:

FilterList filterList = new FilterList();
filterList.addFilter(new FuzzyFilter(...));
filterList.addFilter(new FuzzyFilter(...));
filterList.addFilter(new ColumnPrefixFilter(...));
Scan s = new Scan();
s.setFilter(filterList);

Is there a way I can use MUST_PASS_ONE on the FuzzyFilters and then a MUST_PASS_ALL on the ColumnPrefixFilter combined with the set of FuzzyFilters?

So I'm looking for something like this:

ColumnPrefixFilter AND (FuzzyFilter OR FuzzyFilter)


Solution

  • We can implement two different FilterList to acheive this. Refer the below code

        FilterList mainFilter = new FilterList(FilterList.Operator.MUST_PASS_ALL);
        FilterList subFilter = new FilterList(FilterList.Operator.MUST_PASS_ONE);
    
        subFilter.addFilter(new FuzzyRowFilter(null));
        subFilter.addFilter(new FuzzyRowFilter(null));
    
        mainFilter.addFilter(new ColumnPrefixFilter(Bytes.toBytes("d")));
        mainFilter.addFilter(subFilter);
    

    You can define a mainFilter with MUST_PASS_ALL operator and a subFilter with MUST_PASS_ONE. Now add the filter conditions into subFilter and then add back this subFilter into mainFilter.