hive對接hbase(一)-配置和使用例子

1.配置

配置hive-site.xml,除了增加hive-hbase-handler-xxx.jar之外,在需要進行一些mapreduce計算的時候計算節點還需要hbase的jar來訪問hbase,還要增加其它hbase訪問的jar。

<property>
    <name>hive.aux.jars.path</name>
    <value>file:/opt/hive/lib/hive-hbase-handler-2.3.0.jar,file:/opt/hive/lib/hbase-client-1.1.1.jar,file:/opt/hive/lib/hbase-common-1.1.1.jar,file:/opt/hive/lib/hbase-server-1.1.1.jar,file:/opt/hive/lib/hbase-protocol-1.1.1.jar,file:/opt/hive/lib/htrace-core-3.1.0-incubating.jar,file:/opt/hive/lib/zookeeper-3.4.6.jar</value>
</property>

拷貝hbase-site.xml到hive/conf下面,刪除裏面其他配置,只保留zk配置

<property>
        <name>hbase.zookeeper.quorum</name>
        <value>ht05,ht06,ht07</value>
    </property>
    <property>
        <name>hbase.zookeeper.property.dataDir</name>
        <value>/opt/zookeeper/data</value>
    </property>  

2.實例

##創建表
CREATE TABLE hbase_table_1(key int, value string) 
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:val")
TBLPROPERTIES ("hbase.table.name" = "xyz", "hbase.mapred.output.outputtable" = "xyz");

##插入數據
insert into hbase_table_1 values(1,2);
##查詢數據
select * from hbase_table_1

3.錯誤解決

Throws java.lang.IllegalStateException: unread block data
在使用hive對hbase進行一些mapreduce任務的時候會報這個錯誤,這個錯誤的原因是計算節點上沒有訪問hbase的jar,按照第一步將所有訪問hbase的jar配置到裏面就可以解決問題。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章