首页 > 其他 > 详细

hive与hbase关联表

时间:2015-09-07 12:22:36      阅读:453      评论:0      收藏:0      [点我收藏+]

关于 hbase 和 hive 关联表 详细介绍:


hive 创建 关联hbase表有2种形式:

第一种:
hive> create table hive(id string,name string, age int)
> stored by ‘org.apache.hadoop.hive.hbase.HBaseStorageHandler‘
> with serdeproperties ("hbase.columns.mapping" = ":key,cf:name,cf:age")
> tblproperties ("hbase.table.name" = "hbase");

这种情况是hbase本来没有这张表。hive建表时创建了hbase表.这种情况下,hdfs的hive表目录有hive文件夹,但是里面没有数据(数据时存在hbase里面的)。

hive> insert overwrite table hive
> select * from test;
当hive使用overwrite关键字进行插入数据时。原本数据不会被删除,有同样的行健会被更新覆盖。因为数据是存在hbase中的,遵守hbase插入数据的规则。

当hive删除hive表时,hbase表也会删除。
当先删除hbase的时候,先disabled table,然后drop table
hbase表就被删除了,zookeeper里面也就删除了。
但是hive里面还在,用show tables还能查出来。mysql中TBLS里面还有hive表的信息。但是用select * from hive 查询的时候报错,表不存在(TableNotFoundException)
然后删除hive里面的表的时候会报错TableNotFoundException)。继续show tables时,发现表已经不在了。TBLS里面也没有hive表了。


第二种:external
hive> create external table hive(id string,name string ,ct string)
> stored by ‘org.apache.hadoop.hive.hbase.HBaseStorageHandler‘
> with serdeproperties ("hbase.columns.mapping" = ":key,cf:name,cf:ct")
> tblproperties ("hbase.table.name" = "hbase");

这种情况是hbase里面已经有这张表了,创建一个hive表去管理这hbase表。

hive> insert overwrite table hive
> select * from test;
当hive使用overwrite关键字进行插入数据时。跟第一种情况一样。

删除hive表对hbase没有影响
但是先删除hbase表hive就会报TableNotFoundException
但是删除hive不会报上面这个错。

hive与hbase关联表

原文:http://www.cnblogs.com/bujunpeng/p/4788279.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!