14

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

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

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

Hari Menon
  • 33,649
  • 14
  • 85
  • 108
priya
  • 191
  • 1
  • 1
  • 9

3 Answers3

25

You have to create a FilterList object, and add all the filters you want to that, and set this FilterList object as the filter. You can either 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);
Hari Menon
  • 33,649
  • 14
  • 85
  • 108
8

if you are adding multiple filters then do remember that by default filterlist uses

FilterList.Operator.MUST_PASS_ALL

which means all filter must be passed (AND condition). Use

FilterList.Operator.MUST_PASS_ONE 

if you want to apply OR condition for filters.

user1717259
  • 2,717
  • 6
  • 30
  • 44
ArpanKhandelwal
  • 137
  • 1
  • 5
5

You can use the FilterList object to add your list of filters and can control the order of filters using an ArrayList. Each FilterList takes in only a single operator[OR, AND].But, an hierarchy of filter lists can be created by adding multiple filter list instances with their own operators to a parent filter list.

For example: filters_1 & 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<>();
filterAggregate.add(filterList1);
filterAggregate.add(filterList2);

FilterList filterList3 = new FilterList(FilterList.Operator.MUST_PASS_ALL,filterAggregate);
JoeyHolloway
  • 458
  • 7
  • 19
darkknight444
  • 546
  • 8
  • 21