• 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'

  • 相关阅读:
    【高并发】深度解析ScheduledThreadPoolExecutor类的源代码
    12.Python_行为型模式_观察者模式
    Linux添加、删除用户和用户组
    如何通过内网穿透实现远程连接NAS群晖drive并挂载电脑硬盘?
    动态IP代理是什么?一文看懂动态代理IP
    Kudu知识点
    考虑人机协同的智能工厂多AGV物流调度仿真研究
    用代谢组学解密纳米颗粒缓解烟草重金属中毒机制
    关于 Docker
    不要再说微服务可以解决一切问题了
  • 原文地址:https://blog.csdn.net/libaowen609/article/details/126498969