更改表分区Alter Table Partition

添加分区Add partition

ALTER TABLE table_name ADD [IF NOT EXISTS]
    (PARTITION part_spec [LOCATION path], ...)

part_spec:
    : (part_col_name1=val1, part_col_name2=val2, ...)

向表中添加分区,可以选择为每个添加的分区使用自定义位置。Add partitions to the table, optionally with a custom location for each partition added. 只有那些使用 Hive 格式创建的表支持此功能。This is supported only for tables created using the Hive format. 但从 Spark 2.1 开始,使用数据源 API 定义的表也支持 Alter Table PartitionsHowever, beginning with Spark 2.1, Alter Table Partitions is also supported for tables defined using the datasource API.

IF NOT EXISTS

如果指定的分区已存在,则不会执行任何操作。If the specified partitions already exist, nothing happens.

更改分区Change partition

ALTER TABLE table_name PARTITION part_spec RENAME TO PARTITION part_spec

part_spec:
    : (part_col_name1=val1, part_col_name2=val2, ...)

更改某个分区的分区字段值。Change the partitioning field values of a partition. 仅允许对使用 Hive 格式创建的表执行此操作。This operation is allowed only for tables created using the Hive format.

删除分区Drop partition

ALTER TABLE table_name DROP [IF EXISTS] (PARTITION part_spec, ...)
part_spec:
    : (part_col_name1=val1, part_col_name2=val2, ...)

从表或视图中删除分区。Drop a partition from a table or view. 仅允许对使用 Hive 格式创建的表执行此操作。This operation is allowed only for tables created using the Hive format.

IF EXISTS

如果指定的分区不存在,则不会执行任何操作。If the specified partition does not exists, nothing happens.

设置分区位置Set partition location

ALTER TABLE table_name PARTITION part_spec SET LOCATION path

part_spec:
    : (part_col_name1=val1, part_col_name2=val2, ...)

设置指定分区的位置。Set the location of the specified partition. 仅允许为使用 Hive 格式创建的表设置各个分区的位置。Setting the location of individual partitions is allowed only for tables created using the Hive format.