Hive-创建外部分区表

Hive外部分区表

建表语句

1
2
3
4
5
6
7
8
9
10
11
create external table xxx(
xxx int,
xxx string,
xxx array<bigint>,
xxx struct<aaa:string,bbb:string>
)
partitioned by(pk string) # 分区
row format delimited fields terminated by ',' # 按逗号分隔, text存储时使用
row format serde 'org.apache.hadoop.hive.serde2.JsonSerDe' # json格式的话加上这条, stored选textfile
stored as parquet # 五种类型可选, textfile, sequencefile, rcfile, orcfile, parquet
location '数据地址'

常用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
# 修复分区
msck repair table xxx;
# 添加/删除分区
alter table xxx add partition(pk='xxx') location 'xxxx';
alter table xxx drop partition(pk='xxx');
# 查看分区
show partitions xxx;
# 查看分区结构
desc formatted xxx;
# 查看建表语句
show create table xxxx;
# 查看表字段
describe table;

创建view

kylin只能导入扁平化hive表, 不支持hive复杂数据类型, 导入进去不显示
可通过创建view拍平复杂字段

1
2
3
4
5
create view if not exists xxx
partitioned on (pk)
as
select aaa, bbb, ccc from yyy
lateral view inline(properties) pp_table; # properties是struct结构字段, pp_table是lateral view创建的一张虚拟表

序列化

SerDe是Serialize/Deserilize的简称, 用于序列化和反序列化
用户在建表时可以用自定义的SerDe或者Hive自带的SerDe
例如json文件, 在Hive0.12以上版本使用org.apache.hive.hcatalog.data.JsonSerDe
在Hive3.0开始被添加到Hive Serde中, org.apache.hadoop.hive.serde2.JsonSerDe
预计在Hive4.0中可直接支持为独立的文件格式, 即stored as jsonfile

打赏
  • 版权声明: 本博客所有文章除特别声明外,均采用 Apache License 2.0 许可协议。转载请注明出处!
  • © 2017-2023 王丹鹏
  • Powered by Hexo Theme Ayer
  • 冀ICP备15029707号

请我喝杯咖啡吧~

支付宝
微信