Specify multiple filters in hbase

Is there a way to specify multiple filters during a scan? For example - specify both ColumnFamilyFilter and RowFilter ?

 Filter rowFilter = new RowFilter(CompareFilter.CompareOp.EQUAL, new RegexStringComparator( rowFilterString)); Scan s = new Scan(); s.setFilter(rowFilter); 

I also wanted to add ColumnFilter to s . But it obviously overrides the last filter.

+8
java hbase
source share
3 answers

You need to create a FilterList object and add all the filters you want to this, and set this FilterList object as a filter. You can use the constructor or use the addFilter() method to add filters to the filter list.

 FilterList filterList = new FilterList(); filterList.addFilter(new RowFilter(...)); filterList.addFilter(new ColumnFilter(...)); Scan s = new Scan(); s.setFilter(filterList); 
+18
source share

if you add several filters, remember that the default filter list is used

 FilterList.Operator.MUST_PASS_ALL 

which means that the entire filter must be transferred (condition AND). Use

 FilterList.Operator.MUST_PASS_ONE 

if you want to apply the OR condition to filters.

+7
source share

You can use the FilterList object to add a filter list and control the order of the filters with an ArrayList. Each FilterList accepts only one [OR, AND] statement. But a filter list hierarchy can be created by adding multiple instances of the filter list with their own operators to the list of parent filters.

For example: filters_1 and filters_2 are two filter lists.

 FilterList filterList1 = new FilterList(FilterList.Operator.MUST_PASS_ONE,filters_1) FilterList filterList2 = new FilterList(FilterList.Operator.MUST_PASS_ALL,filters_2) List<Filter> filterAggregate = new ArrayList<Filter(); filterAggregate.add(filterList1) filterAggregate.add(filterList2) FilterList filterList3 = new FilterList(FilterList.Operator.MUST_PASS_ALL,filterAggregate) 
0
source share

All Articles