Versions Compared

Key

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

...

Code Block
languagesql
--Create two tables, partitioned by ds
CREATE TABLE T1(a string, b string) PARTITIONED BY (ds string);
CREATE TABLE T2(a string, b string) PARTITIONED BY (ds string);
ALTER TABLE T1 ADD PARTITION (ds='1');

--Move partition from T1 to T2
ALTER TABLE T2 EXCHANGE PARTITION (ds='1') WITH TABLE T1;


Example Usage – Partial Partition Spec (Exchanging Multiple Partitions)

Code Block
languagesql
--Create two tables with multiple partition partitionscolumns.
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 addADD partitionPARTITION (ds = '1', hr = '00');
ALTER TABLE T1 addADD partitionPARTITION (ds = '1', hr = '01');
ALTER TABLE T1 addADD partitionPARTITION (ds = '1', hr = '03');

--Alter the table, moving partition all the three partitions data where ds='1' from table T1 to table T2 (ds=1) 
ALTER TABLE T2 EXCHANGE PARTITION (ds='1') WITH TABLE T1;

Note that the schema for T1 is being used for the newly created partition T2(ds=1). Either all the partitions of T1 will get created or the whole operation will fail. All partitions of T1 are dropped.

Example Usage – Exchanging Partition Having Multiple

...

Partition Columns

Code Block
languagesql
-- Create two tables, both with multiple partitionspartition columns.
CREATE TABLE t1T1 (a int) PARTITIONED BY (d1 int, d2 int);
CREATE TABLE t2T2 (a int) PARTITIONED BY (d1 int, d2 int);
ALTER TABLE t1T1 ADD PARTITION (d1=1, d2=2);

-- Alter the table, moving partition data d1=1, d2=2 from table T1 to table T2
ALTER TABLE t2T2 EXCHANGE PARTITION (d1 = 1, d2 = 2) WITH TABLE t1T1;