更改表分区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 开始, Alter Table Partitions 还支持使用 DATASOURCE API 定义的表。However, 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.