Reputation: 5397
I have created one hbase-hive table. In which i insert the data through hive.
CREATE TABLE hivetest(cookie string, timespent string, pageviews string, visit string, logdate string)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = "m:timespent, m:pageviews, m:visit, m:logdate")
TBLPROPERTIES ("hbase.table.name" = "hbasetest");
Data is inserted properly. I can access the same data using the hbase shell. But, I have created one hbase client which returns null pointed exception while accessing the same data.
Now the catch is if i create one dummy hbase table and put some data through hbase shell NOT THROUGH HIVE and try to fetch this data from hbase client. It doesn't give the error and return the data. Also, same thing happen if i try to put the data in some row of hbasetest table through hbase client and then try to fetch the same row. Now this time it gives me the data.
So, my question is what is the difference in writing the data through hive and hbase shell?
Hbase Client:
Configuration conf = HBaseConfiguration.create();
Map variables = System.getenv();
conf.set("hbase.zookeeper.quorum","192.168.0.92");
HTable table;
byte family[];
byte qualifier[];
table = new HTable(conf, "hivetest");
family = Bytes.toBytes("m");
qualifier = Bytes.toBytes("logdate");
Get get = new Get(Bytes.toBytes("cookie_value"));
Result r = table.get(get);
byte valueObj[] = r.getValue(family, qualifier);
byte keyObj[] = r.getRow();
String key = new String(keyObj);
String value = new String(valueObj); /* line where exception occur */
System.out.println((new StringBuilder(String.valueOf(key))).append(" = ").append(value).toString());
Exception:
Exception in thread "main" java.lang.NullPointerException
at java.lang.String.<init>(Unknown Source)
at com.hbase.test.HbaseExample.main(HbaseExample.java:51)
Upvotes: 2
Views: 1014
Reputation: 96
Are you using hive version 0.9.0 ? If it's so, that version has a bug. SerDe of HBaseStorageHandler doesn't ignore white space between comma and column family. This makes that names of column families stored are different that you are expecting.
Line 51 in HbaseExample class is that?
byte valueObj[] = r.getValue(family, qualifier);
Try taking off white spaces between comma symbols and column family in SERDEPROPERTIES mapping.
see: https://issues.apache.org/jira/browse/HIVE-3243
Upvotes: 3