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

  • 相关阅读:
    聚焦酷开科技智能大屏OS Coolita,打造智能推荐服务能力全景
    光伏无人机巡检主要有些什么功能和特点?
    异步FIFO
    linux网络协议栈源码分析 - 传输层(TCP连接的建立)
    若依集成easyexcel实现excel表格增强
    nodejs+vue 视频网站的设计与实现
    Docker 基础
    企业架构LNMP学习笔记28
    从十月稻田,看大米为何能卖出200亿市值?
    RSA之前端加密后端解密
  • 原文地址:https://blog.csdn.net/libaowen609/article/details/126498969