Hi Sanjiv!!!! ;)

If you want your keys to be ordered as Integers, why do you not simply
store them as Integers and not as Strings? HBase order the rows
alphabetically, and you can not change that. Yes you can implement a key
comparator if you want but I don't think it's going to change anything to
this situation.

You might want to take a look at this:
http://hbase.apache.org/book/rowkey.design.html

Just put your values that way:

      int myKey = 22000;
      Put put = new Put(Bytes.toBytes(myKey));

And that will solve your ordering problem.

JM




2014-08-27 6:09 GMT-04:00 @Sanjiv Singh <sanjiv.is...@gmail.com>:

> Hi All,
>
> As we know,  All rows are always sorted lexicographically by their row key.
> In lexicographical order, each key is compared at binary level, byte by
> byte and from left to right.
>
> See the example below , where row key is some integer value and output of
> scan show lexicographical order of rows in table.
>
> hbase(main):001:0> scan 'table1'
> ROW        COLUMN+CELL
> 1               column=cf1:, timestamp=1297073325971 ...
> 11             column=cf 1:, timestamp=1297073337383 ...
> 11000        column=cf1 :, timestamp=1297073340493 ...
> 2               column=cf1:, timestamp=1297073329851 ...
> 22             column=cf1:, timestamp=1297073344482 ...
> 22000        column=cf1:, timestamp=1297073333504 ...
> 23             column=cf1:, timestamp=1297073349875 ...
>
> I want to see these rows ordered as integer, not the default way. I can pad
> keys with '0' to get a proper sorting order(i don't like it).
>
> I wanted to see these rows sorted as integer , not just as output of scan
> OR get method , but also to store rows with consecutive integer row keys in
> same block.
>
> Now the question is :
>
>    - Can we define our own custom KeyComparator ?
>    - If Yes , can we enforce it for PUT method ?  so that rows would be
>    stored as new KeyComparator.
>    - Can we plug this comparator duriong SCAN method to change order of
>    result rows ?
>
> Hope, i have explained the proplem well,  seeking for your valuable
> response on it.
>
>
> Regards
> Sanjiv Singh
> Mob :  +091 9990-447-339
>

Reply via email to