phoenix-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anil gupta <anilgupt...@gmail.com>
Subject Re: BigDecimal casting issue?
Date Thu, 26 Feb 2015 13:44:08 GMT
Hi Matthew,

If you want phoenix to read a BigDecimal value out of HBase. You will need
to use PDataType.DECIMAL.toBytes(BigDecimal) to serialize that value in
HBase. IMO, serialization of of BigDecimal via PDataType is better because
it enables byte array comparison on BigDecimal values.

Thanks,
Anil

On Thu, Feb 26, 2015 at 4:30 AM, Gabriel Reid <gabriel.reid@gmail.com>
wrote:

> Hi Matt,
>
> Although the object representation of the Phoenix DECIMAL type is
> BigDecimal, the byte-level encoding is different than that of
> Bytes.toBytes(BigDecimal). The reason for this is to allow for
> ordering of these values based comparison of binary values. Sorting
> the values with binary value comparison based on the return value of
> Bytes.toBytes(BigDecimal) will not result in the correct ordering of
> values.
>
> As you may have noticed, many data types in Phoenix have an UNSIGNED_*
> counter part which uses the same underlying encoding as Bytes.toBytes,
> although these datatypes suffer from the same binary comparison issue
> as outlined above.
>
> - Gabriel
>
>
>
> On Thu, Feb 26, 2015 at 12:06 PM, Matthew Johnson
> <matt.johnson@algomi.com> wrote:
> > Hi all,
> >
> >
> >
> > I am trying to map an HBase column where I store java.math.BigDecimal
> values
> > using:
> >
> >
> >
> > Bytes.toBytes(myBigDecimalValueInJava)
> >
> >
> >
> > My understanding from the “Data Types” page
> > (http://phoenix.apache.org/language/datatypes.html#decimal_type) is
> that the
> > DECIMAL type in Phoenix should map to this. However, when I store:
> >
> >
> >
> > 102.1
> >
> >
> >
> > in HBase, Phoenix reads it back as:
> >
> >
> >
> > -1.02020201E+126
> >
> >
> >
> > Not sure whether I am using it wrong? I have tried creating the view with
> > data type DECIMAL and also DECIMAL(15,5) but both give the same problem.
> Is
> > anyone else able to successfully insert BigDecimal values via the HBase
> > client and retrieve them using Phoenix?
> >
> >
> >
> > FYI when I retrieve the value using HBase client:
> >
> >
> >
> > BigDecimal bd = Bytes.toBigDecimal(value);
> >
> >
> >
> > It correctly prints the value of 102.1.
> >
> >
> >
> > Any thoughts?
> >
> >
> >
> > Cheers,
> >
> > Matt
> >
> >
> >
> >
>



-- 
Thanks & Regards,
Anil Gupta

Mime
View raw message