How to Update/Drop a Hive Partition?

darcyq picture darcyq · Dec 11, 2012 · Viewed 218.3k times · Source

After adding a partition to an external table in Hive, how can I update/drop it?

Answer

darcyq picture darcyq · Dec 18, 2012

You can update a Hive partition by, for example:

ALTER TABLE logs PARTITION(year = 2012, month = 12, day = 18) 
SET LOCATION 'hdfs://user/darcy/logs/2012/12/18';

This command does not move the old data, nor does it delete the old data. It simply sets the partition to the new location.

To drop a partition, you can do

ALTER TABLE logs DROP IF EXISTS PARTITION(year = 2012, month = 12, day = 18);

Hope it helps!