Question

I have a Hbase "User" table. Now I have the row keys of User table but I want to get only those user whose dateOfBirth is grater then a "Valid Date" and belongs to the key List.

Currently I am using

  Result[] result = table.get(keys);

for getting all users whose keys I have.

I am new in Hbase. Please help.

Thanks

Was it helpful?

Solution

You can try something like this:

import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.filter.FilterList;
import org.apache.hadoop.hbase.filter.CompareFilter;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;

FilterList fl = new FilterList();
Filter filter = new SingleColumnValueFilter(Bytes.toBytes("columnFamily"), Bytes.toBytes("column"), CompareFilter.CompareOp.GREATER, Bytes.toBytes(dateOfBirth));
fl.add(filter);
scan.setFilter(fl);

ResultScanner rs = table.getScanner(scan);

You can get more info about filters in http://hbase.apache.org/book/client.filter.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top