hivehiveql

How to Update/Drop a Hive Partition?


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


Solution

  • 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);