我已經創建了一個hbase-hive表。我通過配置單元插入數據。通過hive插入從hbase讀取數據的問題
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");
數據被正確地插入。我可以使用hbase shell訪問相同的數據。但是,我創建了一個在訪問相同數據時返回空指針異常的hbase客戶端。
現在,如果我創建一個虛擬hbase表,並通過hbase shell將一些數據不通過HIVE,並嘗試從hbase客戶端獲取此數據。它不會給出錯誤並返回數據。 此外,如果我嘗試通過hbase客戶端將數據放在hbasetest表的某個行中,然後嘗試獲取同一行,則會發生同樣的情況。現在這次它給了我數據。
所以,我的問題是通過配置單元和hbase shell編寫數據有什麼不同?
HBase的客戶:
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 in thread "main" java.lang.NullPointerException
at java.lang.String.<init>(Unknown Source)
at com.hbase.test.HbaseExample.main(HbaseExample.java:51)
感謝很多人.... :) – Naresh
歡迎您... GBY – chech0x