hive 映射hbase
前提是放三个jar包(jar包寻找方法https://editor.csdn.net/md/?articleId=117664094)放到hive/lib 目录下
设置events库变量db
set hivevar:db=events;
hive中 创建hbase映射表 hb_hbase
create external table ${db}.hb_users(
user_id String,
birth_year int,![在这里插入图片描述](https://img-blog.csdnimg.cn/20210608093743995.png)
gender String,
locale String,
location String,
time_zone String,
joined_at String
)
stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
with serdeproperties ('hbase.columns.mapping'=':key,
profile:birth_year,profile:gender,region:locale,
region:location,region:time_zone,registration:joinAt'
)
tblproperties ('hbase.table.name'='event_db:users');
一定要查看内容,表建成了,后面还有坑
select * from hb_user limit 5;
第一个报错是说版本不对,果断查看jar包发现jar包的版本给太低了
换了,因为我的mongodb是 4开头的比较高 那么jar包版本尽量找高的 (咋找https://blog.csdn.net/qq_15009447/article/details/117692979)
将低版本的删掉,放入高版本的jar包,重新执行select语句,成功。
第二个报错是因为查询的表还是 映射表 hive 映射的hbase表,所以要开启hbase 才能出结果。当然可以继续建hive本地表来查询
创建内部表,将hb_users外部数据 以ORC的格式存储到hive内部表users中,提高读取效率
create table ${db}.users
stored as orc as
select * from ${db}.hb_users;
查询本地表
select * from users limit 10;