You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by vishnu <vi...@pointcross.com> on 2012/11/23 12:46:28 UTC

PrefixFilter is not working with long in HBase

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
|


Re: PrefixFilter is not working with long in HBase

Posted by David Koch <og...@googlemail.com>.
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 <vi...@pointcross.com> 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
> |
>
>