Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify multiple filters in hbase

Tags:

java

hbase

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.

like image 840
priya Avatar asked Aug 26 '13 11:08

priya


2 Answers

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);
like image 88
Hari Menon Avatar answered Oct 21 '22 22:10

Hari Menon


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.

like image 40
ArpanKhandelwal Avatar answered Oct 21 '22 23:10

ArpanKhandelwal