I'm using incr
to increment a counter column in table.Now I need to filter certain records in scan
so that counter is less than some value(say 1).get
show the counter value(which is 4) for a particular row-key in hbase shell as below:
column=q:counter, timestamp=1419403701427, value=\x00\x00\x00\x00\x00\x00\x00\x04
Now if use scan filter to filter exclude this record from scan as below
{FILTER=> "SingleColumnValueFilter('q','counter',<,'binary:1',true,true)" , COLUMNS=>['q:counter'] }
Above specify record with counter value 4 is still shown in scan result.
I have tried true
,false
as third parameter of SingleColumnValueFilter
.
Do I need to specify 1 in byte format or so?
For HBase the column value is just a byte[]
so it's a bit tricky to make the query with the HBase Shell because the standard filter language will convert everything to strings:
http://www.cloudera.com/content/cloudera/en/documentation/core/latest/topics/admin_hbase_filtering.html
To make it work with integers/longs we have to think of it as if we would do with JAVA: convert the value to a byte[]
and feed it to a SingleColumnValueFilter with a CompareOp.
First you have to import the required libraries into HBase Shell
import java.lang.Long
import org.apache.hadoop.hbase.util.Bytes
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter
import org.apache.hadoop.hbase.filter.CompareFilter
import org.apache.hadoop.hbase.filter.BinaryComparator
To find rows with a value LESS than BINARY value of 20L \x00\x00\x00\x00\x00\x00\x00\x14
scan "your_table", {LIMIT => 10, FILTER => SingleColumnValueFilter.new(Bytes.toBytes('Family'), Bytes.toBytes('Column'), CompareFilter::CompareOp.valueOf('LESS'), BinaryComparator.new(Bytes.toBytes(Long.parseLong("20"))))}
For integer columns the solution is a little easier (no Long parsing required). To find rows with a value LESS than BINARY value of 20 \x00\x00\x00\x14
scan "your_table", {LIMIT => 10, FILTER => SingleColumnValueFilter.new(Bytes.toBytes('Family'), Bytes.toBytes('Column'), CompareFilter::CompareOp.valueOf('LESS'), BinaryComparator.new(Bytes.toBytes(20)))}
Valid compare operators:
- EQUAL
- GREATER
- GREATER_OR_EQUAL
- LESS
- LESS_OR_EQUAL
- NO_OP
- NOT_EQUAL