• Hbase和Hive整合


    一、环境整合

    1.1、环境配置

    执行命令vi  /etc/profile 配置hive和hbase的环境变量

     1.2、导入依赖

    由于 Hive 要连接到 HBase, 所以 Hive 需要知道 HBase 的一些jar 包,所以在 hive-env.sh 中添加一行如下配置:

    export HIVE_AUX_JARS_PATH=/data/soft/hbase-2.3.2/lib

    或是直接把jar拷贝到hive包/lib里面

    1. cp /data/soft/hbase-2.3.2/lib/hbase-common-2.3.2.jar /data/soft/apache-hive-3.1.2-bin/lib
    2. cp /data/soft/hbase-2.3.2/lib/hbase-server-2.3.2.jar /data/soft/apache-hive-3.1.2-bin/lib
    3. cp /data/soft/hbase-2.3.2/lib/hbase-client-2.3.2.jar /data/soft/apache-hive-3.1.2-bin/lib
    4. cp /data/soft/hbase-2.3.2/lib/hbase-protocol-2.3.2.jar /data/soft/apache-hive-3.1.2-bin/lib
    5. cp /data/soft/hbase-2.3.2/lib/hbase-it-2.3.2.jar /data/soft/apache-hive-3.1.2-bin/lib
    6. cp /data/soft/hbase-2.3.2/lib/hbase-hadoop2-compat-2.3.2.jar /data/soft/apache-hive-3.1.2-bin/lib
    7. cp /data/soft/hbase-2.3.2/lib/hbase-hadoop-compat-2.3.2.jar /data/soft/apache-hive-3.1.2-bin/lib

    1.3 修改相关配置文件

     1.4 启动相关服务

    二、关联Hive和HBase数据

    建立 Hive 表,关联 HBase 表,插入数据到 Hive 表的同时能够影响 HBase表。

    2.1 在 Hive 中创建表同时关联 HBase

    1. CREATE TABLE hive_hbase_emp_table(
    2. empno int,
    3. ename string,
    4. job string,
    5. mgr int,
    6. hiredate string,
    7. sal double,
    8. comm double,
    9. deptno int
    10. )
    11. STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
    12. WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,info:ename,info:job,info:mgr,info:hiredate,info:sal,info:comm,info:deptno")
    13. TBLPROPERTIES ("hbase.table.name" = "hbase_emp_table");

    其中 org.apache.hadoop.hive.hbase.HBaseStorageHandler 类主要用于将hive与hbase关联,在hivez中创建的表会映射到hbase数据库中

    在 Hive 和 HBase 中分别查看是否生成了相应的表.

    2.2 创建Hive 临时中间表   

    由于不能将数据直接插入与hbase关联的hive表中,所以需要创建中间表   

    1. CREATE TABLE emp_tmp(
    2. empno int,
    3. ename string,
    4. job string,
    5. mgr int,
    6. hiredate string,
    7. sal double,
    8. comm double,
    9. deptno int
    10. )
    11. row format delimited fields terminated by '\t';

    把数据导入临时表中 

    load data local inpath '/data/soft/hivedata/emp.txt' into table emp_tmp

    2.3 通过insert命令将临时中间表的数据导入到hive_hbase_emp_table中

    insert into table hive_hbase_emp_table select * from emp_tmp

    2.4 查看数据是否同步

    Hive :  select * from hive_hbase_emp_table;

    HBase:  scan 'hbase_emp_table'

  • 相关阅读:
    Python装饰器扫盲
    docker基线安全修复和容器逃逸修复
    C/C++输出第二个整数 2019年9月电子学会青少年软件编程(C/C++)等级考试一级真题答案解析
    RabbitMQ-08 不公平分发与预取值
    【JMeter】threadNum:将接口查询结果列表按顺序赋值给各线程
    【实战】硅基物语.AI写作高手:从零开始用ChatGPT学会写作
    springboot配置
    计算机毕业设计ssm+vue基本微信小程序的高校科研管理系统
    台湾IB国际学校介绍
    C8051F020 SMBus一直处于busy状态解决办法
  • 原文地址:https://blog.csdn.net/libaowen609/article/details/126498969