THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
The tables have different schemas. Their partitions cannot be exchanged
Syntax
Code Block | ||
---|---|---|
| ||
ALTER TABLE <source_table> EXCHANGE PARTITION (<(partial)?partition spec>) WITH TABLE <dest_table> |
Example usage - Basic
Code Block | ||
---|---|---|
| ||
--Create two tables, one partitioned by ds, one not partitioned CREATE TABLE T1(a string, b string) PARTITIONED BY (ds string); CREATE TABLE T2(a string, b string); --Exchange partition data from T1 to T2(ds=1) ALTER TABLE T1 EXCHANGE PARTITION (ds='1') WITH TABLE T2 |
...
Example usage - Partial partition spec
Code Block | ||
---|---|---|
| ||
--Create two tables with multiple partitions. CREATE TABLE T1(a string, b string) PARTITIONED BY (ds string, hr string); CREATE TABLE T2(a string, b string) PARTITIONED BY (ds string, hr string); ALTER TABLE T1 add partition (ds = '1', hr = '00'); ALTER TABLE T1 add partition (ds = '1', hr = '01'); ALTER TABLE T1 add partition (ds = '1', hr = '03'); --Alter the table, moving partition data where ds='1' from table T1 to table T2 (ds=1) ALTER TABLE T1 EXCHANGE PARTITION (ds='1') WITH TABLE T2 |
...