RAVITEJA SATYAVADA
RAVITEJA SATYAVADA

Reputation: 2571

Altering a table partition

I have a table with a partition. I have loaded the data into that table. Now, Is it possible to drop the partition from that table, with out deleting the data that have been loaded?

Upvotes: 0

Views: 690

Answers (1)

anon
anon

Reputation:

Yes. You can create a second table with the same schema and swap the empty table out for your current partition.

-- create tables
CREATE TABLE t1 (a string, b string) partitioned by (ds string);
CREATE TABLE t2 (a string, b string);

-- then swap partitions
ALTER TABLE t1 EXCHANGE PARTITION (ds = '1') WITH TABLE t2;

The other approach is to create a new, empty, partition:

ALTER TABLE sales
PARTITION (country = 'US', year = 2012, month = 12, day = 22)
SET LOCATION = 'sales/partitions/us/2012/12/22' ;

With either approach, your data will still be present. I wrote an introduction to hive partitioning a while back that should be helpful.

Upvotes: 1

Related Questions