My complete test code. It should be helpful for you.
----------------
public static void testHBase() throws IOException {
byte[] cfBytes = Bytes.toBytes("cf");
byte[] qBytes = Bytes.toBytes("q");
Configuration conf = new Configuration();
conf.set(HConstants.ZOOKEEPER_CLIENT_PORT, "40060");
conf.set(HConstants.ZOOKEEPER_QUORUM,
"10.232.98.94,10.232.98.72,10.232.98.40");
conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/hbase-cdh4");
HTable htable = new HTable(conf, "datax_hbasebulkwriter_target_2w");
for (int i = 0; i < 10; i++) {
Put put = new Put(Bytes.toBytes(i));
if (i < 5) {
put.add(cfBytes, qBytes, Bytes.toBytes(i));
} else {
put.add(cfBytes, qBytes, Bytes.toBytes(-i));
}
htable.put(put);
}
Scan scan = new Scan(Bytes.toBytes(0), Bytes.toBytes(10));
FilterList filterList = new FilterList();
SingleColumnValueFilter filter = new SingleColumnValueFilter(
cfBytes,
qBytes,
CompareFilter.CompareOp.GREATER_OR_EQUAL,
Bytes.toBytes(1));
filterList.addFilter(filter);
filter = new SingleColumnValueFilter(
cfBytes,
qBytes,
CompareFilter.CompareOp.LESS,
Bytes.toBytes(Integer.MIN_VALUE));
filterList.addFilter(filter);
scan.setFilter(filterList);
ResultScanner rs = htable.getScanner(scan);
Result r = rs.next();
while (r != null) {
System.out.println(Bytes.toInt(r.getColumnLatest(cfBytes,
qBytes).getValue()));
r = rs.next();
}
htable.close();
}
----------------
Console output:
1
2
3
4
Process finished with exit code 0
----------------
On Wed, Mar 19, 2014 at 8:33 PM, praveenesh kumar <[email protected]>wrote:
> I am not sure if this can helps - https://github.com/ndimiduk/orderly
>
> This API supports negative keys, as far as I know. You can give it a try,
> its simple to implement your keys using this API
>
> Regards
> Prav
>
>
> On Wed, Mar 19, 2014 at 12:26 PM, Chaitanya <[email protected]
> >wrote:
>
> > Hi Ramkrishna,
> >
> > There is one more problem, i.e. I don't have the rights to add anything
> to
> > the hbase jar.
> > The problem with writing a custom comparator is that we have to add it to
> > the jar so that its available to all the hbase region servers.
> > Please correct me if I am wrong.
> > Thanks
> >
> >
> >
> > -----
> > Regards,
> > Chaitanya
> > --
> > View this message in context:
> >
> http://apache-hbase.679495.n3.nabble.com/Filters-failing-to-compare-negative-numbers-int-float-double-or-long-tp4057268p4057279.html
> > Sent from the HBase User mailing list archive at Nabble.com.
> >
>
--
Best Regards,
Haosdent Huang