当前位置:   article > 正文

Hbase--Hbase数据表映射到Hive中_怎么将hbase的表映射到hive的内部表中

怎么将hbase的表映射到hive的内部表中

  HBase是一种非关系型分布式数据库,无法进行多表关联等关系型数据库能执行的操作,但是基于HBase高容量,高吞吐的特征,我们可以将HBase的表映射到Hive中进行存储,下面展示存储案例.

一:准备HBase数据表

1.创建命名空间
create_namespace 'testConnectHive'
2.命名空间内创建一个student表,列族分别为stuinfo,schoolinfo
create 'testConnectHive:student','stuinfo','schoolinfo'
3.表内插入数据
  1. hbase(main):004:0> put 'testConnectHive:student','1001','stuinfo:stuname','zhangsan'
  2. Took 0.6039 seconds
  3. hbase(main):005:0> put 'testConnectHive:student','1001','stuinfo:stuno','1001'
  4. Took 0.0107 seconds
  5. hbase(main):006:0> put 'testConnectHive:student','1001','stuinfo:stugender','male'
  6. Took 0.1695 seconds
  7. hbase(main):007:0> put 'testConnectHive:student','1001','schoolinfo:schoolname','beijingdaxue'
  8. Took 0.0342 seconds
  9. hbase(main):008:0> put 'testConnectHive:student','1001','schoolinfo:schoollocation','beijing'
4.查看数据表
desc 'testConnectHive:student'

二.HBase数据表映射到Hive中

1.开启远程服务
nohup hive --service hiveserver2 &
2.Hive创建表,映射HBase数据表
  1. create database testConnectHive;
  2. use testConnectHive;
  3. create external table student(
  4. id string,
  5. stuname string,
  6. stuno string,
  7. schoolname string,
  8. schoollocation string
  9. )stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' with
  10. serdeproperties ('hbase.columns.mapping'=':key,stuinfo:stuname,stuinfo:stuno,schoolinfo:schoolname,schoolinfo:schoollocation')
  11. tblproperties ('hbase.table.name'='testConnectHive:student');
  12. select * from student;
3.此时可以查看到Hive表内结构数据
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/78939
推荐阅读
相关标签
  

闽ICP备14008679号