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

1.配置

配置hive-site.xml,除了增加hive-hbase-handler-xxx.jar之外,在需要进行一些mapreduce计算的时候计算节点还需要hbase的jar来访问hbase,还要增加其它hbase访问的jar。

<property>
    <name>hive.aux.jars.pathname>
    <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.jarvalue>
property>

拷贝hbase-site.xml到hive/conf下面,删除里面其他配置,只保留zk配置

<property>
        <name>hbase.zookeeper.quorumname>
        <value>ht05,ht06,ht07value>
    property>
    <property>
        <name>hbase.zookeeper.property.dataDirname>
        <value>/opt/zookeeper/datavalue>
    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配置到里面就可以解决问题。

你可能感兴趣的:(hive,hbase,hive-sql,on,hadoop技术)