zoukankan      html  css  js  c++  java
  • Hive 整合 HBase Binge

    为何 Hive 要整合 HBase

    HBase 不支持标准 SQL 语句,而且 HBase 做统计分析也不支持 Join 表操作,而这些功能是 Hive 所具备的,所以在实际的生产环境中将二者整合并让 HBase 表中的数据可以使用 Hive SQL 语句及 Join 分析是很有必要的。

    整合步骤

    注:进入了 hive 的 shell 命令行界面

    1. 指定 hive 中 hbase 的 zookeeper 的访问路径
    set hbase.zookeeper.quorum=node-01:2181,node-02:2181,node-03:2181;
    
    2. 指定 hbase 在 zookeeper 中存储数据的节点
    set zookeeper.znode.parent=/hbase;
    
    3. 将 hive-habse 整合的 jar 包放在 hive 的 classpath 下
    add jar /root/apps/hive-3.1.2/lib/hive-hbase-handler-3.1.2.jar;
    

    整合完成:)

    验证

    1. 在 HBase 中建表
    hbase(main):001:0> create 't_hive_hbase','base_info','extra_info'
    Created table t_hive_hbase
    Took 1.9468 seconds
    => Hbase::Table - t_hive_hbase
    
    # 插入表数据
    hbase(main):002:0> put 't_hive_hbase','001','base_info:name','zhangsan'
    Took 2.3504 seconds
    hbase(main):003:0> put 't_hive_hbase','001','base_info:age','28'
    Took 0.0128 seconds
    hbase(main):004:0> put 't_hive_hbase','001','extra_info:phone','13500412502'
    
    
    2. 在 Hive 中建表并关联 HBase 表
    create external table t_hive_hbase(rowkey string, base_info map<string, string>, extra_info map<string, string>) 
    row format delimited fields terminated by '\t' 
    stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
    with serdeproperties ("hbase.columns.mapping" = ":key,base_info:,extra_info:") 
    tblproperties ("hbase.table.name" = "t_hive_hbase");
    

    必要的参数解释:

    • hbase.columns.mapping:指定 HBase 和 Hive 表的字段的映射关系
    • :key:获取 rowkey
    • base_info:列名:获取 base_info:列名的值,不写就是默认获取全部
    • extra_info:列名:获取 extra_info:列名的值,不写就是默认获取全部
    2. 在 Hive 中执行 SQL 查询
    select * from t_hive_hbase;
    
    +----------------------+---------------------------------+--------------------------+
    | t_hive_hbase.rowkey  |     t_hive_hbase.base_info      | t_hive_hbase.extra_info  |
    +----------------------+---------------------------------+--------------------------+
    | 001                  | {"age":"28","name":"zhangsan"}  | {"phone":"13500412502"}  |
    +----------------------+---------------------------------+--------------------------+
    
    作者:Binge
    本文版权归作者和博客园共有,转载必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
  • 相关阅读:
    windows下 文件资源管理器 的操作
    Visual Studio Code 折叠代码快捷键
    windows 10 取消alt+tab的预览功能
    String.prototype.replace
    Webpack的tapable 为什么要使用 new Funtion 来生成静态代码
    Visual Studio Code 断点调试Nodejs程序跳过node内部模块(internal modules)
    【社群话题分享】有哪些奇葩的技术人员考核方式?
    工信部要求应用商店上新 App 检查 IPv6,这里有一份 IPv6 快速部署指南
    读完这篇文章,5G 就没有秘密了
    双剑合璧——掌握 cURL 和 Dig 走天涯
  • 原文地址:https://www.cnblogs.com/binbingg/p/15720009.html
Copyright © 2011-2022 走看看