简体   繁体   中英

RowFilter in HBase

I have 20 rows in an HBase table and the rowkey is in long format starting from 1 to 20. I want to query the records from this where the rowkey starts with 1. I tried with PrefixFilter and BinaryPrefixComparator but it is working fine only if the rowkey is in string fromat. if it is in long the query returns all the records. How can I achieve this?

Filter expression

Scan scan=new Scan();
Filter rowFilter=new RowFilter(CompareOp.EQUAL, new BinaryPrefixComparator(Bytes.toBytes("1")));
//Filter rowFilter=new RowFilter(CompareOp.NOT_EQUAL, new BinaryPrefixComparator(Bytes.toBytes("1")));
scan.setFilter(rowFilter);
ResultScanner resultscanner=htable.getScanner(scan);

If the row keys are long , you have to refer them as long in your query rather than String.
Ie: instead of Bytes.toBytes("1") use Bytes.toBytes(1L) .

You can set the range to be scanned:

scan.setStartRow(Bytes.toBytes(1L));
scan.setStopRow(Bytes.toBytes(21L));  //since stopRow is exclusive

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM