Renaming a Partition – Hive

Tables in Apache Hive are partitioned similarly to SQL. Partitioning is a method of dividing a table into chunks based on the values of particular columns. In comparison, creating and managing partitions in Hive is much easier. Partitions are typically specified when a table is created; however, in this post, we will explain how to alter and rename the existing partition.

Consider the below example. For the sample data, click here.

    CREATE TABLE CitiesList(Id INT, Name STRING)
    PARTITIONED BY (Country STRING);

    LOAD DATA LOCAL INPATH ‘Desktop/Docs/UK_Cities.txt’
    OVERWRITE INTO TABLE CitiesList
    PARTITION (Country=’UK’);

    LOAD DATA LOCAL INPATH ‘Desktop/Docs/US_Cities.txt’
    OVERWRITE INTO TABLE CitiesList
    PARTITION (Country=’US’);

    LOAD DATA LOCAL INPATH ‘Desktop/Docs/UAE_Emirates.txt’
    OVERWRITE INTO TABLE CitiesList
    PARTITION(Country=’UAE’);

Using the aforementioned approach, we created a table, defined the partitioned column, and loaded the data. Now, let’s change the name of an existing partition.

    ALTER TABLE CitiesList PARTITION (Country=’UAE’)
RENAME TO PARTITION (Country=’AE’);

Hope you find this article helpful.

Please subscribe for more interesting updates.

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s