标签:style class blog code http color
<property> <name>hive.aux.jars.path</name> <value>file:///home/spark/app/hive-0.12.0-cdh5.0.0/lib/hive-hbase-handler-0.12.0-cdh5.0.0.jar,file:///home/spark/app/hive-0.12.0-cdh5.0.0/lib/zookeeper-3.4.5-cdh5.0.0.jar,file:///home/spark/app/hive-0.12.0-cdh5.0.0/lib/hbase-common-0.96.1.1-cdh5.0.0.jar,file:///home/spark/app/hive-0.12.0-cdh5.0.0/lib/hbase-client-0.96.1.1-cdh5.0.0.jar,file:///home/spark/app/hive-0.12.0-cdh5.0.0/lib/hbase-server-0.96.1.1-cdh5.0.0.jar,file:///home/spark/app/hive-0.12.0-cdh5.0.0/lib/hbase-protocol-0.96.1.1-cdh5.0.0.jar,file:///home/spark/app/hive-0.12.0-cdh5.0.0/lib/htrace-core-2.01.jar</value> </property>
需要将除了hive-hbase-handler之外所有的jar包从$HBASE_HOME/lib下拷贝到$HIVE_HOME/lib下
启动hive:推荐使用hive -hiveconf hive.root.logger=DEBUG,console启动,可以看到更加详细的日志信息
案例一:操作简单表单cf
创建hive-hbase表:
CREATE TABLE hive_hbase_table_kv(key string, value string) STORED BY ‘org.apache.hadoop.hive.hbase.HBaseStorageHandler‘ WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:val") TBLPROPERTIES ("hbase.table.name" = "hbase_hive_table_kv");
创建hive表并导入数据
CREATE TABLE kv (key STRING, value STRING); LOAD DATA LOCAL INPATH ‘/home/spark/app/spark-1.0.0-bin-2.3.0-cdh5.0.0/examples/src/main/resources/kv1.txt‘ OVERWRITE INTO TABLE kv; INSERT OVERWRITE TABLE hive_hbase_table_kv SELECT key, value FROM kv;
查看hive和hbase发现均创建了表,并且在两边均能查询到数据。
案例二:操作简单表多cf
CREATE TABLE hbase_table_2(key string, value1 string, value2 string, value3 string) STORED BY ‘org.apache.hadoop.hive.hbase.HBaseStorageHandler‘ WITH SERDEPROPERTIES ( "hbase.columns.mapping" = ":key,a:b,a:c,d:e" );
b/c字段属于a列族,e属于d列族。
导入hive表数据:INSERT OVERWRITE TABLE hbase_table_2 SELECT empno, ename, job, deptno FROM emp;
案例三:操作分区表
CREATE TABLE hbase_table_3(key string, ename string, job string, sal double) partitioned by(pt string) STORED BY ‘org.apache.hadoop.hive.hbase.HBaseStorageHandler‘ WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,a:b,a:c,d:e") TBLPROPERTIES ("hbase.table.name" = "hbase_table_3");
导入hive数据:
INSERT OVERWRITE TABLE hbase_table_3 PARTITION(pt=‘2013-08-01‘) SELECT empno, ename, job, sal FROM emp;
注意事项:
与hbase整合的有分区的表在使用hive查询时存在问题: select * from table查询不显示数据,select column from table可以查到数据
为什么select * from xxx 不显示数据?
select * from xxx在普通表中是直接读取HDFS文件,而使用hive-hbase-handler的方式来导入数据的时候,数据是存放在hbase的hdfs上;
在这里是直接从HBase进行查询。查询是成功了,但是hive并不会展示。
hive-hbase-handler方式导入hive表数据到hbase表中,布布扣,bubuko.com
hive-hbase-handler方式导入hive表数据到hbase表中
标签:style class blog code http color
原文地址:http://www.cnblogs.com/luogankun/p/3810557.html