Exchange Partition
Created by Namit Jain, last modified by Lefty Leverenz on Jan 28, 2014
Exchange Partition
It is proposed as part of https://issues.apache.org/jira/browse/HIVE-4095. Once this is implemented, it should be part of the Language Manual DDL.
The idea is similar to this.
The high level idea is as follows:
alter table <tablename> exchange partition (<(partial)?partition spec>) with table <tablename> |
The semantics of the above statement is that the data is moved from the target table to the source table. Both the tables should have the same schema. The operation fails in the presence of an index. The source table should not have that partition. Consider the following examples:
create table T1(a string, b string) partitioned by (ds string); create table T2(a string, b string); |
The operation
alter table T1 exchange partition (ds='1') with table T2 |
moves the data from T2 to T1@ds=1. The operation fails if T1@ds=1 already exists or T1 and T2 have different schemas. Note that the schema for T2 is being used for the newly created partition T1@ds=1.
create table T1(a string, b string) partitioned by (ds string, hr string); create table T2(a string, b string) partitioned by (hr string); |
The operation
alter table T1 exchange partition (ds='1') with table T2 |
moves the data from T2 to T1@ds=1. The operation fails if T1@ds=1 already exists or T1 and T2 have different schemas. Note that the schema for T2 is being used for the newly created partition T1@ds=1. Either all the partitions of T1 will get created or the whole operation will fail. All partitions of T2 are dropped.