0
votes

I have a Hbase table that has looks something like

cf:col1 | cf:col2
----------------- 
   A    |   1
   A    |   2
   B    |   1
   B    |   2

I want to filter the results of a scan where depending depending on the value of col1. Specifically I only want the records where (col1 is 'A' and col2 is '1') OR (col1 is 'B' and col2 is '2'). Is there a way to do this using standard filters? I am doing this through a Java MapReduce job.

1

1 Answers

1
votes

You can use two SingleColumnValueFilters.

Scan scan = new Scan();
FilterList filterList = new FilterList();
filterList.addFilter(new SingleColumnValueFilter(Bytes.toBytes("cf"), Bytes.toBytes("col1"), CompareOp.NOT_EQUAL, Bytes.toBytes("1")));
filterList.addFilter(new SingleColumnValueFilter(Bytes.toBytes("cf"), Bytes.toBytes("col2"), CompareOp.NOT_EQUAL, Bytes.toBytes("1")));
//Set whether entire row should be filtered if column is not found.
filter.setFilterIfMissing(false);
scan.setFilter(filterList);

From shell

scan 'yourTable' ,{ FILTER => "SingleColumnValueFilter('cf','col1',=, 'binary:1') AND SingleColumnValueFilter('cf','col2',=, 'binary:1')" }