用hive外部表访问hbase数据
来源:互联网 发布:2018年网络dj歌曲 编辑:程序博客网 时间:2024/05/22 15:20
在hbase中创建表后,我们只能在hbase shell中使用scan查询数据,这对于熟悉SQL的使用者不怎么习惯,不过我们可以在hive中创建外部表来访问hbase表中的数据,例子如下:
1.这里hbase中的表oss_user_label_action_data已经存在
=> #<#<Class:0xd922e1>:0xd5a1b0>
hbase(main):067:0> scan 'oss_user_label_action_data',LIMIT=>1
ROW COLUMN+CELL
201407|31130101|8613500000001 column=info:areacode, timestamp=1415243857802, value=22
201407|31130101|8613500000001 column=info:cardtype, timestamp=1415243857802, value=1
201407|31130101|8613500000001 column=info:createtime, timestamp=1415243857802, value=20141028 11:18:34
201407|31130101|8613500000001 column=info:enable_flag, timestamp=1415243857802, value=0
201407|31130101|8613500000001 column=info:extstring, timestamp=1415243857802, value=
201407|31130101|8613500000001 column=info:labelno, timestamp=1415243857802, value=31130101
201407|31130101|8613500000001 column=info:labelvalue, timestamp=1415243857802, value=9693
201407|31130101|8613500000001 column=info:modifytime, timestamp=1415243857802, value=20141028 11:18:45
201407|31130101|8613500000001 column=info:monthno, timestamp=1415243857802, value=201407
201407|31130101|8613500000001 column=info:provcode, timestamp=1415243857802, value=1
201407|31130101|8613500000001 column=info:usernumber, timestamp=1415243857802, value=8613500000001
1 row(s) in 0.0580 seconds
2.创建外部表
CREATE EXTERNAL TABLE hive_oss_user_label_action_data(
key string,
monthno string,
usernumber string,
labelno string,
labelvalue string,
provcode string,
areacode string,
cardtype string,
extstring string,
createtime string,
modifytime string
)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES
("hbase.columns.mapping" =
":key,info:monthno,info:usernumber,info:labelno,info:labelvalue,info:provcode,info:areacode,info:cardtype,info:extstring,info:createtime,info:modifytime")
TBLPROPERTIES("hbase.table.name" = "oss_user_label_action_data");
注意hbase.columns.mapping后面的字段直接不能出现空格和换行.
3.通过hive查询数据
根据rowkey查询
select * from hive_oss_user_label_action_data where key='201407|31130101|8613500000001'
根据某个字段查询
select * from hive_oss_user_label_action_data where usernumber='8613500000001'
组合查询
select * from hive_oss_user_label_action_data where usernumber='8613500000001' and labelno='31130101'
说明:
这里我们访问的hive_oss_user_label_action_data表是虚表,数据是存储在hbase中的,我们可以创建另外一个hive中的表,
将hbase中的数据加载到hive本地
创建另外一个表
CREATE TABLE hive_oss_user_label_action_data_local(
key string,
monthno string,
usernumber string,
labelno string,
labelvalue string,
provcode string,
areacode string,
cardtype string,
extstring string,
createtime string,
modifytime string
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
STORED AS TEXTFILE;
将hbase中的表数据加载到本地表
INSERT OVERWRITE TABLE hive_oss_user_label_action_data_local SELECT * FROM hive_oss_user_label_action_data;
-- The End --
1.这里hbase中的表oss_user_label_action_data已经存在
=> #<#<Class:0xd922e1>:0xd5a1b0>
hbase(main):067:0> scan 'oss_user_label_action_data',LIMIT=>1
ROW COLUMN+CELL
201407|31130101|8613500000001 column=info:areacode, timestamp=1415243857802, value=22
201407|31130101|8613500000001 column=info:cardtype, timestamp=1415243857802, value=1
201407|31130101|8613500000001 column=info:createtime, timestamp=1415243857802, value=20141028 11:18:34
201407|31130101|8613500000001 column=info:enable_flag, timestamp=1415243857802, value=0
201407|31130101|8613500000001 column=info:extstring, timestamp=1415243857802, value=
201407|31130101|8613500000001 column=info:labelno, timestamp=1415243857802, value=31130101
201407|31130101|8613500000001 column=info:labelvalue, timestamp=1415243857802, value=9693
201407|31130101|8613500000001 column=info:modifytime, timestamp=1415243857802, value=20141028 11:18:45
201407|31130101|8613500000001 column=info:monthno, timestamp=1415243857802, value=201407
201407|31130101|8613500000001 column=info:provcode, timestamp=1415243857802, value=1
201407|31130101|8613500000001 column=info:usernumber, timestamp=1415243857802, value=8613500000001
1 row(s) in 0.0580 seconds
2.创建外部表
CREATE EXTERNAL TABLE hive_oss_user_label_action_data(
key string,
monthno string,
usernumber string,
labelno string,
labelvalue string,
provcode string,
areacode string,
cardtype string,
extstring string,
createtime string,
modifytime string
)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES
("hbase.columns.mapping" =
":key,info:monthno,info:usernumber,info:labelno,info:labelvalue,info:provcode,info:areacode,info:cardtype,info:extstring,info:createtime,info:modifytime")
TBLPROPERTIES("hbase.table.name" = "oss_user_label_action_data");
注意hbase.columns.mapping后面的字段直接不能出现空格和换行.
3.通过hive查询数据
根据rowkey查询
select * from hive_oss_user_label_action_data where key='201407|31130101|8613500000001'
根据某个字段查询
select * from hive_oss_user_label_action_data where usernumber='8613500000001'
组合查询
select * from hive_oss_user_label_action_data where usernumber='8613500000001' and labelno='31130101'
说明:
这里我们访问的hive_oss_user_label_action_data表是虚表,数据是存储在hbase中的,我们可以创建另外一个hive中的表,
将hbase中的数据加载到hive本地
创建另外一个表
CREATE TABLE hive_oss_user_label_action_data_local(
key string,
monthno string,
usernumber string,
labelno string,
labelvalue string,
provcode string,
areacode string,
cardtype string,
extstring string,
createtime string,
modifytime string
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
STORED AS TEXTFILE;
将hbase中的表数据加载到本地表
INSERT OVERWRITE TABLE hive_oss_user_label_action_data_local SELECT * FROM hive_oss_user_label_action_data;
-- The End --
阅读全文
0 0
- 用hive外部表访问hbase数据
- 1008-Hive访问HBase表数据
- hive 访问hbase表
- hive 访问hbase 表
- SparkSQL读取HBase数据,通过自定义外部数据源(hbase的Hive外关联表)
- Hadoop 从零开始学习系列-hive与hbase外部关联表建立及数据导入
- 通过hive访问hbase中的表
- 通过hive访问hbase中的表
- Greenplum或DeepGreen中使用外部表访问Hive数据(分隔符是Hive表默认列分隔符)
- hive建hbase外部表,内部表的问题
- 填坑之路:记一次hive外部表查询hbase的long类型数据出现乱码问题
- Hive表数据导入到Hbase
- hive和hbase表数据同步
- Hive表数据导入到Hbase
- Hive数据导入HBase
- hive处理hbase数据
- HBASE数据导入HIVE
- hive导出hbase数据
- 设置开发板的IP
- hibernate配置文件头所在包中的位置
- NetBeans IDE品鉴
- Apache Httpd 2.4.27 下载与安装
- 一个利用CAN实现车辆控制的简单模板
- 用hive外部表访问hbase数据
- 去除input默认的加减号
- 非交互检测远程端口(非nc)
- 连续子数组的最大和
- 消息队列ActiveMQ的安装与使用
- Android通过输入暗码控制指定app icon的显示与隐藏
- 选字验证码
- 原型链模式图解1 .2 .5
- Linux常用命令学习