phoenix-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Taylor <jamestay...@apache.org>
Subject Re: numeric formats
Date Thu, 30 Oct 2014 16:38:13 GMT
Hi Mike,
Yes, the bit configuration is different in Phoenix to ensure that the
sort order of the binary representation matches the natural sort order
of the data. This improves Phoenix performance by allowing many more
query optimizations than would otherwise be possible.

You can convert back/forth in SQL using the CAST operator[1] like this:

    SELECT CAST(my_int AS UNSIGNED_INT) FROM my_table

You can convert in Java using our PDataType class, like this:

    int myInt = PDataType.INT.toObject(bytes, offset);
    byte[] hbaseBytes = PDataType.UNSIGNED_INT.toBytes(myInt);

There are numerous other less simple/more performant ways to do this
conversion, depending on your needs.

Another alternative may be to use our Pig Loader/Store functions which
handle this conversion automatically, or to take a similar approach
and have a custom serde for the application you're reading/writing too
so that it can work with the Phoenix serialized format directly.

Thanks,
James

[1] http://phoenix.apache.org/language/index.html#cast

On Thu, Oct 30, 2014 at 7:14 AM, Mike Friedman <Mike.Friedman@ds-iq.com> wrote:
> Hi,
>
>
>
> It seems like the Phoenix formats for numerics like integer, float, are
> different, in terms of the bit configurations, than the way non-Phoenix
> HBase clients store and interpret numerics. Unsigned numbers are the same,
> but when they’re signed the representations appear to be different. Is there
> a way using Java to convert from the Phoenix numeric formats to/from the
> conventional HBase formats?
>
>
>
> Thanks.
>
>
>
>
>
> Mike

Mime
View raw message