Reputation: 53
I understood that from the HBase shell it is possible to create compound filters like (Filter1 AND Filter2) OR (Filter3 AND Filter4)
.
Ref: http://www.cloudera.com/documentation/enterprise/5-6-x/topics/admin_hbase_filtering.html
But in java I only found FilterList.Operator.MUST_PASS_ALL
and FilterList.Operator.MUST_PASS_ONE
operators to define how filters will be processed.
In my case I'd like to define a Scan which will perform some QualifierFilter
only on some specific rows using RowFilter
.
ex: if rowkey contains "$today", filter out the Column Families having the Qualifier "number_eggs_produced because it is too early. Else do not filter it.
(!RowFilter) OR (RowFilter AND QualifierFilter)
For the moment I found 2 bad workarounds :
I filter manually the data in the results :
ResultScanner scanner = table.getScanner(scan);
for (Result result = scanner.next(); result != null; result = scanner.next())
{
for (Cell cell : result.listCells())
{
String row = Bytes.toString(CellUtil.cloneRow(cell));
long qualifier = Long.valueOf(Bytes.toString(CellUtil.cloneQualifier(cell)));
double value = Double.valueOf(Bytes.toString(CellUtil.cloneValue(cell)));
if(row ... )
I hope I'm clear.
Thanks !
Upvotes: 3
Views: 210
Reputation: 3785
A FilterList
is composable. The two different operators let you create AND
lists and OR
lists. For example:
FilterList andFilter = new FilterList(Operator.MUST_PASS_ALL);
FilterList orFilter = new FilterList(Operator.MUST_PASS_ONE);
Scan scan = new Scan();
scan.setFilter(orFilter);
orFilter.addFilter(rowFilter1);
orFilter.addFilter(andFilter); // composition
andFilter.addFilter(rowFilter2);
andFilter.addFilter(rowFilter3);
This is the logical equivalent of (rowFilter1 || (rowFilter2 && rowFilter3))
Upvotes: 4