栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

HBASE与HIVE转换

HBASE与HIVE转换

hive-to-hbase

在hive中建表
create table if not exists employee (
uid int,
uname string,
age int,
sex string,
province string
)
stored by 'org.apache.hadoop.hive.hbase.HbaseStorageHandler'
with serdeproperties(
"hbase.columns.mapping"=":key,base_info:name,base_info:age,base_info:sex,address:provice"
)
tblproperties(
"hbase.table.name"="mydb:employee"
);

导入数据

注意,要使用动态导入数据,不能使用load。

如果想要导入大数据集,可以借助中间表进行动态导入
insert into .....  select ...... from ...

当然:也可以在hbase中直接put数据

hbase-to-hive

drop table mydb2.t1;
create external table if not exists mydb2.t1(
uid string,
uage int,
uname string,
usex string,
province string
)
stored by 'org.apache.hadoop.hive.hbase.HbaseStorageHandler'
with serdeproperties(
"hbase.columns.mapping"=":key,f1:age,f1:name,f1:gender,f2:province"
)
tblproperties(
"hbase.table.name"="ns1:t1"
);

查询
select * from mydb2.t1;

主要事项

1. 映射hbase的列时,要么就写:key,要么不写,默认使用:key
2. hbase中表存在的时候,在hive中创建表时应该使用external关键字。
3. 如果删除了hbase中对应的表数据,那么hive中就不能查询出来数据。
4. hbase中的列和hive中的列个数和数据类型应该尽量相同,hive表和hbase表的字段不是按照名字匹配,而是按照顺序来匹配的。
5. hive、hbase和mysql等可以使用第三方工具来进行整合。
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/389313.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号