Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
HBase, mail # user - Using doubles and longs as ordering row values


Copy link to this message
-
Re: Using doubles and longs as ordering row values
anil gupta 2012-11-05, 22:57
Hi Jonathan,

If possible try to avoid using Double for rowkey because Double has
precision problems.
Here is more details about problems with double:
1.
http://stackoverflow.com/questions/12699040/double-vs-long-serialization-in-java
2.
http://stackoverflow.com/questions/179427/how-to-resolve-a-java-rounding-double-issue

You might get wrong results due problems in Double. You can use two long or
int to store the decimal value as RowKey.

HTH,
Anil Gupta
On Mon, Nov 5, 2012 at 11:38 AM, Jean-Daniel Cryans <[EMAIL PROTECTED]>wrote:

> On Mon, Nov 5, 2012 at 10:41 AM, Jonathan Bishop <[EMAIL PROTECTED]>
> wrote:
> > Hi,
> >
> > In my application my row values are doubles. I would like my scans to
> > traverse the rows in order of increasing values.
> >
> > But if I simply use
> >
> > double d  = ....
> > byte[] row = Bytes.toBytes(d);
> >
> > I will get an ordering which is based on the byte values of doubles, not
> on
> > the value of the doubles themselves.
>
> It's the same ordering as long as you don't use negative values.
>
> >
> > I see also that integer values have the same issue due to the first bit
> > being the sign bit. So negative values will come after positive values.
> >
> > Any suggestions?
>
> Don't use row keys that can be negative? :)
>
> Also don't use a single number as a row key, see
> http://hbase.apache.org/book.html#rowkey.design
>
> J-D
>

--
Thanks & Regards,
Anil Gupta