Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The tables have different schemas. Their partitions cannot be exchanged

 

Syntax 
Code Block
languagesql
ALTER TABLE <source_table> EXCHANGE PARTITION (<(partial)?partition spec>) WITH TABLE <dest_table>


Example usage - Basic

Code Block
languagesql
--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
languagesql
--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 

...