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
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?
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")));
If the row keys are
long, you have to refer them as
long in your query rather than String.
I.e: instead of
You can set the range to be scanned:
scan.setStartRow(Bytes.toBytes(1L)); scan.setStopRow(Bytes.toBytes(21L)); //since stopRow is exclusive