在配置单元中为年、月和日创建表分区

oxf4rvwz  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(350)

我的数据文件夹位于下面的结构中,包含2年的数据(2015-2017)。
appdata/contryname/year/month/day/app1.json
例如:
appdata/india/2016/07/01/geek.json
appdata/india/2016/07/02/geek.json
appdata/us/2016/07/01/geek.json
现在我已经创建了一个带有分区的外部表。

PARTITIONED BY (Country String, Year String, Month String, day String)

在此之后,我需要在alter table语句中添加分区。

ALTER TABLE mytable 
ADD PARTITION (country='India', year='2016',month='01', day='01') 
location 'AppData/India/2016/07/01/'

不可能每天都创建添加分区脚本,
有什么最简单的方法可以做到这一点吗?

vohkndzv

vohkndzv1#

msck repair table mytable ,但不使用当前的目录命名约定

演示

猛击

hdfs dfs -mkdir -p /AppData/country=India/year=2016/month=07/day=01 
hdfs dfs -mkdir -p /AppData/country=India/year=2016/month=07/day=02
hdfs dfs -mkdir -p /AppData/country=US/year=2016/month=07/day=01

Hive

create table mytable (i int) 
partitioned by (country string, year string, month string, day string)
location '/AppData'
;
hive> msck repair table mytable;
OK
Partitions not in metastore:    mytable:country=India/year=2016/month=07/day=01 mytable:country=India/year=2016/month=07/day=02 mytable:country=US/year=2016/month=07/day=01
Repair: Added partition to metastore mytable:country=India/year=2016/month=07/day=01
Repair: Added partition to metastore mytable:country=India/year=2016/month=07/day=02
Repair: Added partition to metastore mytable:country=US/year=2016/month=07/day=01
hive> show partitions mytable;
OK
partition
country=India/year=2016/month=07/day=01
country=India/year=2016/month=07/day=02
country=US/year=2016/month=07/day=01

相关问题