Hi,
If your row keys really are really longs, i.e stored as: Long.getBytes()
and NOT Long.toString().getBytes() than you could just use:
Filter rowFilter = new RowFilter(CompareOp.LESS, new
BinaryComparator(Bytes.toBytes(20L)))
You can verify how row keys are stored by doing:
scan '<your_table_name>', {LIMIT =>1}
in HBase shell. If your row keys show up as \x escaped HEX than you stored
longs, if they are human readable, you stored the string representation of
a long instead and you'll have to do it your way.
/David
On Fri, Nov 23, 2012 at 12:46 PM, vishnu <[email protected]> wrote:
> Hello users,
>
> I have 20 rows in an HBase table and the rowkey is in long format starting
> from 1 to 20. I want to query from this table with the condition like 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);
>
> Regards,
> Vishnu
> |
>
>