Adding multiple partitions at once – Hive

Is it possible to add multiple partitions to a table in Apache Hive at the same time?

If you’re using version 0.7 or older, the answer is NO. One division should be added at a time.

The answer is YES if you’re running version 0.8 or later.

Tables are divided into partitions using Apache Hive. Partitioning divides a table into divisions based on the values of specific columns such as date (month, year,etc) , region, and sector.

ALTER TABLE ADD PARTITION is used to add partitions to a table. The partition values should only be quoted if they are strings. A directory holding data files must be the destination.

Syntax:
ALTER TABLE table_name
ADD [IF NOT EXISTS] PARTITION partition_spec [LOCATION ‘location’]
[, PARTITION partition_spec [LOCATION ‘location’], …];

Example:
ALTER TABLE tbPopulationData ADD
PARTITION (city=’San Antonio’, country=’us’) location ‘/path/to/us/sanantonio’
,PARTITION (city=’San Diego’, country=’us’) location ‘/path/to/us/sandiego’;

The above command will help in creating two new partitions to the table.

Hope you find this article helpful.

Subscribe to our mailing list to be notified of new articles.

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 )

Facebook photo

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

Connecting to %s