vim /export/datas/hive-hbase.txt
1,zhangsan,802,lisi,603,wangwu,304,zhaoliu,70
创建测试表
--创建测试数据库
create database course;--切换数据库
use course;--创建原始数据表
create external table if not exists course.score(
id int,
cname string,
score int) row format delimited fields terminated by ',' stored as textfile ;--加载数据文件
load data local inpath '/export/datas/hive-hbase.txt' into table score;
创建一张Hive与HBASE的映射表
create table course.hbase_score(
id int,
cname string,
score int)
stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
withserdeproperties("hbase.columns.mapping"="cf:name,cf:score")tblproperties("hbase.table.name"="hbase_score");
将测试表的数据写入映射表
insert overwrite table course.hbase_score select id,cname,score from course.score;
如果Hbase中表已存在,只能创建外部表【比较常用的方式】
create external table course.stu(key string,
name string,
age string,
phone string
)row format serde 'org.apache.hadoop.hive.hbase.HBaseSerDe'
stored by'org.apache.hadoop.hive.hbase.HBaseStorageHandler'with serdeproperties("hbase.columns.mapping"=":key,basic:name,basic:age,other:phone")
tblproperties("hbase.table.name"="student:stu");-- count计数
hbase org.apache.hadoop.hbase.mapreduce.RowCounter 'student:stu'-- 查看数据
scan 'student:stu',{LIMIT=>5}
get 'student:stu',1