Hive-1.2.2操作HBase-1.1.10

原创
2017/06/14 20:28
阅读数 86

Hive与HBase整合

1、在安装好HBase的服务器上安装Hive

2、配置环境变量HBASE_HOME=<hbase-install-dir>

3、进入Hive Cli,创建与HBase相关联的表即可

# 在hive中创建表t_event,会在hbase中同步创建表event
CREATE TABLE t_event(id string, channel_id string, item_id string, time timestamp, type string, user_id string, value double)
    STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
 	WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,event:channel_id,event:item_id,event:time,event:type,event:user_id,event:value")
 	TBLPROPERTIES ("hbase.table.name" = "event");


# hive操作已经存在的hbase。使用CREATE EXTERNAL TABLE:
CREATE EXTERNAL TABLE t_event(id string, channel_id string, item_id string, time timestamp, type string, user_id string, value double)
    STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
 	WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,event:channel_id,event:item_id,event:time,event:type,event:user_id,event:value")
 	TBLPROPERTIES ("hbase.table.name" = "event");

4、若HBase中存储的数据是int、long等非string类型转换后的字节数组,则在进行hive映射时需指明"hbase.table.default.storage.type" = "binary",如下

CREATE EXTERNAL TABLE t_event(id string, channel_id string, item_id string, time timestamp, type string, user_id string, value double)
    STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
 	WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,event:channel_id,event:item_id,event:time,event:type,event:user_id,event:value","hbase.table.default.storage.type" = "binary")
 	TBLPROPERTIES ("hbase.table.name" = "event");

# 或者使用下面的写法(HBase列名后加#b)
CREATE EXTERNAL TABLE t_event(id string, channel_id string, item_id string, time timestamp, type string, user_id string, value double)
    STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
 	WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,event:channel_id,event:item_id,event:time,event:type,event:user_id,event:value#b")
 	TBLPROPERTIES ("hbase.table.name" = "event");
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部