hadoophiveqlhadoop-partitioningapache-hive

How to rename all partition columns in hive


When I am trying to rename all partition columns in an existing table for date range of one year which are partitioned - this is what I am getting.

hive> ALTER TABLE test.usage PARTITION ('date') RENAME TO PARTITION (partition_date);

FAILED: ValidationFailureSemanticException Partition spec {partition_date=null} contains non-partition columns.

I got that syntax from here: 1


Solution

  • Given that I am not 100% sure if what you want is to rename the value of the partition or actually change the column which the table is partitioned.

    Let's suppose you want to rename the partition's value.

    There is an issue in Hive 0.13 and in Hive 0.14 is working fine. Anyways, this should work:

    set fs.hdfs.impl.disable.cache=false; 
    set fs.file.impl.disable.cache=false; 
    

    Now run the query by setting this property.

    > hive> set fs.hdfs.impl.disable.cache=false;  
    > hive> set fs.file.impl.disable.cache=false;
    > hive> ALTER TABLE test.usage PARTITION (date='oldValue') RENAME TO PARTITION (date='newValue');
    

    Let's suppose you want to change the partition column

    In this case what you will need to do is to recreate the table changing the column which the table will be partitioned.

    Note: Remember that if you already had data inside the partitions, you will need to reinsert the data.

    Please see also this answer