Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Plain View
HBase >> mail # user >> PrefixFilter is not working with long in HBase


+
vishnu 2012-11-23, 11:46
Copy link to this message
-
Re: PrefixFilter is not working with long in HBase
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
> |
>
>
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB