文章目录
HBase数据的准备
表:event_db:users
表结构
表数据
Hive建表和导入
创建库:create database events
设置临时变量代表 events:set hivevar:db=events;
设置动态分区非严格模式:set hive.exec.dynamic.partition.mode=nonstrict;
设置允许动态分区:set hive.exec.dynamic.partition=true;
关闭自动mapjoin:set hive.auto.convert.join=false;
创建外部表:
【注意字段顺序一一对应】
create external table ${db}.hb_users(
user_id string,
birth_year int,
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:birthyear,
profile:gender,
region:locale,
region:location,
region:timezone,
registration:joinedAt')
tblproperties ('hbase.table.name'='event_db:users');
创建内部表users,将hb_users外部数据以ORC格式存储到HDFS中
create table ${db}.users
stored as orc as
select * from ${db}.hb_users;
删除外部表
drop table ${db}.hb_users;