Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create HBbase Compound filters in java

Tags:

java

filter

hbase

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 started to write a Customer filter but probably it is already supported as the shell must call java code and I don't see it.
  • 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 !

like image 335
Shazz Avatar asked Mar 16 '26 19:03

Shazz


1 Answers

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))

like image 141
Martin Serrano Avatar answered Mar 18 '26 08:03

Martin Serrano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!