創(chuàng)建Hive表的同時(shí)創(chuàng)建HBase表挂谍,插入數(shù)據(jù)到Hive表的同時(shí)能夠影響HBase表
1述呐、emp.txt數(shù)據(jù)
http://www.reibang.com/p/1d1ecf881a72
2、在Hive中創(chuàng)建表同時(shí)關(guān)聯(lián)HBase
hive> 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");
尖叫提示:完成之后,可以分別進(jìn)入Hive和HBase查看,都生成了對(duì)應(yīng)的表
3、在Hive中創(chuàng)建臨時(shí)中間表绳姨,用于load文件中的數(shù)據(jù)
hive> create table emp(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int)
row format delimited fields terminated by '\t';
尖叫提示:不能將數(shù)據(jù)直接load進(jìn)Hive所關(guān)聯(lián)HBase的那張表中
4、向Hive中間表中l(wèi)oad數(shù)據(jù)
hive> load data local inpath '/opt/software/emp.txt' into table emp;
5阔挠、通過insert命令將中間表中的數(shù)據(jù)導(dǎo)入到Hive關(guān)聯(lián)HBase的那張表中
hive> insert into table hive_hbase_emp_table select * from emp;
6飘庄、查看Hive以及關(guān)聯(lián)的HBase表中是否已經(jīng)成功的同步插入了數(shù)據(jù)
Hive
hive> select * from hive_hbase_emp_table;
HBase
hbase> scan 'hbase_emp_table'