当前位置: 动力学知识库 > 问答 > 编程问答 >

java - 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.
I.e: 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
分享给朋友:
您可能感兴趣的文章:
随机阅读: