Hive HBase集成

1 篇文章 0 订阅

1.版本

    hive0.14

    hbase0.99.2

2.编译

    由于hive0.14版本不支持hbase0.99.2,所以需要对hive源码中的hbase-handler模块中的相关类做修改,重新编译。

2.1 修改 /hbase-handler/src/java/org/apache/hadoop/hive/hbase/HBaseStorageHandler.java 类470行

TableMapReduceUtil.addDependencyJars(
    jobConf, HBaseStorageHandler.class, TableInputFormatBase.class,
 org.cliffc.high_scale_lib.Counter.class); // this will be removed for HBase 1.0
将org.cliffc.high_scale_lib.Counter.class参数去掉。

2.2 修改/hbase-handler/src/java/org/apache/hadoop/hive/hbase/HiveHBaseInputFormatUtil.java 类

在该类中添加方法

+import org.apache.hadoop.hbase.TableName;
+  public static TableName getTableName(JobConf jobConf) throws IOException {
+    String hbaseTableName = jobConf.get(HBaseSerDe.HBASE_TABLE_NAME);
+    return TableName.valueOf(Bytes.toBytes(hbaseTableName));
+  }

2.3 修改 /hbase-handler/src/java/org/apache/hadoop/hive/hbase/HiveHBaseTableInputFormat.java 类

+import org.apache.hadoop.hbase.client.ConnectionFactory;
+import org.apache.hadoop.hbase.client.Connection;

 

93行

-    setHTable(HiveHBaseInputFormatUtil.getTable(jobConf));
+    final Connection conn = ConnectionFactory.createConnection(jobConf);
+
+    initializeTable(conn, HiveHBaseInputFormatUtil.getTableName(jobConf));

111行

       public void close() throws IOException {
         recordReader.close();
+        conn.close();
       }

 

362行

 

+    final Connection conn = ConnectionFactory.createConnection(jobConf);

+      InputSplit [] results = null;

+try{

+    initializeTable(conn, HiveHBaseInputFormatUtil.getTableName(jobConf));
-    setHTable(new HTable(HBaseConfiguration.create(jobConf), Bytes.toBytes(hbaseTableName)));

 

+       results = new InputSplit[splits.size()];

-   InputSplit[] results = new InputSplit[splits.size()];

 

         for (int i = 0; i < splits.size(); i++) { 
               results[i] = new HBaseSplit((TableSplit) splits.get(i), tablePaths[0]);
           }
+     } finally{
+           conn.close();
+     }

2.4 maven编译hive

 

3.配置

编辑hive/conf/hive-env.sh

将hive和hbase的lib包加入到hive的环境变量中。

如下

export HIVE_AUX_JARS_PATH=${HIVE_HOME}/lib;${HBASE_HOME}/lib

 

4.demo

4.1hive建表

CREATE TABLE hbase_hive_1(key int, value string) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping"=":key,cf:val") TBLPROPERTIES ("hbase.table.name"="hivehbase1");

在hive中建表hbase_hive_1,映射hbase中的表为hivehbase1,执行此命令同时建了hive和hbase的表。


hive外部表

CREATE EXTERNAL TABLE hbase_hive_1(key int, value string) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping"=":key,cf:val") TBLPROPERTIES ("hbase.table.name"="hivehbase");

hbase中已经有hivehbase表,执行hive的建外部表命令。

 

4.2插入数据

insert overwrite table hbase_hive_1 values(1,'aaaa');


4.3查询数据

select * from hbase_hive_1


5.性能测试

参考http://lxw1234.com/archives/2015/04/101.htm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值