业务背景
mobile_log记录移动日志,现在需要将其保存到hive表中,将来可以按日期,小时进行统计,为此,需要建立一张具有日期、小时的hive分区表。
业务实现
hive分区表分为单分区表和多分区表,一个表可以拥有多个分区,每个分区都以文件夹的形式单独存放在表的文件目录下,详细可以参见Hive LanguageManual DDL
建立多分区表代码
drop table if exists pms.test_mobile_log;
create table pms.test_mobile_log
(
id bigint,
infomation string
)
partitioned by (ds string, hour string)
row format delimited fields terminated by '\t'
lines terminated by '\n';
导入数据到多分区表中,实现方式有如下这些:
- 建表的时候,就插入数据,参考: