hive集成hbase之创建映射表的两种方式

  1. 创建内部表(这种方式可以在hbase中创建新表)

 

CREATE TABLE hive_hbase_sal(id int,name string,sal int,deptno int) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,info:name,info:sal,info:deptno ") TBLPROPERTIES ("hbase.table.name" = "hbase_sal ");

 

 

2. 在hive中创建外部表(关键词external)(这种方式可以关联hbase中已经存在的表)

 

create external table hive_hbase_customer(iid int,id int,name string)stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' with serdeproperties("hbase.columns.mapping"=":key,id:id,name:name") tblproperties("hbase.table.name"="customer");

 

注:无论以上那种方式创建的映射表均不能直接写入数据,需要通过创建中间表来完成数据的插入;

3.向映射表写入数据

① 创建中间表

create table customer_put(iid int,id int,name string) row format delimited fields terminated by ';';

② 导入数据到中间表

load data local inpath'/export/data/input.txt' overwrite into table customer_put;

 

③ 导入数据到映射表

insert overwrite/into table hive_hbase_customer select * from customer_put;

 

insert into 将数据追加到映射表,主键相同的数据不会重复追加,但会作更新

insert overwrite 覆盖掉映射表原有的数据

④ hbase中查看customer表

scan 'customer';

 

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值