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 <[email protected]> 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 > > > >
