Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created 08-08-2016 04:11 PM
I have Hbase table with integer field.
When I map Phoenix table on to this Hbase table, integer field show values like : -213456236
E.g.
hbase> create 'emp','f1' hbase> put 'emp',1,'f1:eid',1001
Corresponding Phoenix table:
Create table "emp" (pk integer primary key, "f1"."eid" integer);
When I try to select from emp table, I get large number in eid field:
select "eid" from "emp"; => 299345678
This is happening for float values also. Whereas varchar values get populated correctly.
What wrong am I doing? Am I wrongly mapping the Hbase table to phoenix? I have followed steps from FAQ page.
I have read below question, but unable to get any clue.
Please help @Josh Elser
Created 08-12-2016 01:11 PM
I'm planning to use approach mentioned below using phoenix-pig integration.
https://community.hortonworks.com/questions/12538/phoenix-storage-in-pig.html
Created 08-08-2016 04:15 PM
You should use Apache Phoenix's APIs for writing data to Phoenix tables. There is often special encoding of values in these tables. Integers are one example. They are stored as a sequence of 4 bytes (with a sign bit) to ensure that they sort properly. The "string" form of the integer is being parsed as a number.
Created 08-08-2016 04:19 PM
Thank for the reply Josh.
My use-case is: Data is going to get populated into Hbase table.
I'm going to create a Phoenix table on top of Hbase table so that I can fire SQL on it.
So I'm going to just read data from Phoenix table.
Created 08-08-2016 04:45 PM
Ok, beware that you are going down an unsupported path. You may be able to use the HBase Bytes class for properly converting data in your write-side, but I am not sure if this will be 100% accurate.
Created 08-09-2016 09:08 AM
@Saurabh Rathi, the workaround , you can do is to declare your field "eid" as VARCHAR and use TO_NUMBER function to cast it to number during query if required.
Or, @Josh Elser said, while storing the data in hbase , you can encode your integer to phoenix representation of INT by using below API.(same for other data types)
byte[] byte_representation = PInteger.INSTANCE.toBytes(<integer_value>);
Please see for more details:-
https://phoenix.apache.org/faq.html#How_I_map_Phoenix_table_to_an_existing_HBase_table
Created 08-09-2016 10:44 AM
Thanks for the reply @Ankit Singhal
I am populating Hbase table through Hive table.
CREATE TABLE sdm_report__301__301_hive (order_by bigint, virus_id bigint, virus_name string, server_date date)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ('hbase.columns.mapping' = ':key, family:vid, family:name, family:server_date')
TBLPROPERTIES ('hbase.table.name' = 'sdm_report__301__301_hbase');
INSERT OVERWRITE TABLE sdm_report__301__301_hive SELECT * FROM sdm_report__301__301;
How should I use API you mentioned while inserting data into Hbase table through Hive?
Is there a way to map 'PInteger' class datatype while creating Hbase table?
Or is there a way to directly create Phoenix table through Hive?
Created 08-09-2016 02:38 PM
Probably only by making your own Hive UDF. The VARCHAR and TO_NUMBER approach would be simplest.
Created 08-11-2016 01:01 PM
Can I use PhoenixStorageHandler while creating Hive table?
Mentioned here:
Created 08-11-2016 03:15 PM
I'm not sure of the state of that repository, but such a feature is included in Apache Phoenix 4.8.0 and will be included in HDP 2.5. I would assume that the integration would handle this natively, but I am not positive.
Created 08-16-2016 08:47 AM
As Josh already mentioned, it's included in Apache Phoenix 4.8.0. And it would handle it correctly. One additional note - the implementation that was accepted in Apache Phoenix is a bit different. More information can be found there: https://github.com/mini666/hive-phoenix-handler