8.2.2 案例1

目标

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


步骤1:在 Hive 中创建表同时关联 HBase

CREATE TABLE hive_hbase_emp_table(
    empno int,
    ename string,
    job string,
    mgr int,
    hiredate string,
    sal double,
    comm double,
    deptno int
)
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,info:ename,info:job,info:mgr,info:hiredate,info:sal,info:comm,info:deptno")
TBLPROPERTIES ("hbase.table.name" = "hbase_emp_table");

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


步骤2: 建立临时表

建立中间表, 并向中间表插入数据. 从中间表查询数据,并把数据插入到hive_hbase_emp_table表中

CREATE TABLE emp_tmp(
    empno int,
    ename string,
    job string,
    mgr int,
    hiredate string,
    sal double,
    comm double,
    deptno int
)
row format delimited fields terminated by '\t';

load data local inpath '/opt/module/datas/emp.txt' into table emp_tmp;

步骤3: 在 Hive 中向 hive_hbase_emp_table插入数据

insert into table hive_hbase_emp_table select * from emp_tmp;

步骤4: 查看数据是否同步

Hive :

select * from hive_hbase_emp_table;

HBase:

scan 'hbase_emp_table'
Copyright © 尚硅谷大数据 2019 all right reserved,powered by Gitbook
该文件最后修订时间: 2018-11-20 18:14:19

results matching ""

    No results matching ""