Shazz
Shazz

Reputation: 53

How to create HBbase Compound filters in java

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 hope I'm clear.

Thanks !

Upvotes: 3

Views: 210

Answers (1)

Martin Serrano
Martin Serrano

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

Related Questions