Hive Partition(分区)DDL操作
add partition
ADD PARTITION会更改表元数据,但不会加载数据。如果分区位置中不存在数据,查询时将不会返回结果。
因此需要保证增加的分区位置路径下,数据已经存在,或者增加分区之后导入分区数据。
# 1. 增加分区
alter table table_name add partition (dt='20170101') location
# 一次添加一个分区
alter table table_name add partition (dt='2008-08-08', country='us') location '/path/to/us/part080808' partition (dt='2008-08-09', country='us') location 'path/to/us/part080809';
# 一次添加多个分区
rename partition
alter table table_name partition partition_soec rename to partition partition_spec;
alter table table_name partition (dt='2008-08-09') rename to partition (dt='20080809');
delete partition
删除表的分区。这将删除该分区的数据和元数据。
# 删除分区
alter table table_name drop [if exists] partition (dt='2008-08-08', country='us');
# 直接删除数据 不进垃圾桶
alter table table_name drop [if exists] partition (dt='2008-08-08', country='us') purge;
alter partition
# 修改分区
# 更改分区文件存储格式
alter table table_name partition (dt='2008-08-09') set fileformat file_format;
# 更改分区位置
alter table table_name partition (dt='2008-08-09') set location 'new location';