How to update or drop a Hive Partition? - Big Data In Real World

How to update or drop a Hive Partition?

How to set variables in Hive scripts?
December 14, 2020
How to fix the Hive metastore database is not initialized issue?
December 18, 2020
How to set variables in Hive scripts?
December 14, 2020
How to fix the Hive metastore database is not initialized issue?
December 18, 2020

It is a common use case in your production jobs or Hive scripts to update or drop a Hive partition from your table. Let’s see how to update Hive partitions first and then see how to drop partitions and few variations of the same.

Update a Hive partition

Let’s say you had an issue with the way the data was loaded into a partition and now you have found a way to fix the data and fixed it. The corrected date is under hdfs://user/svc_account/fixed_date/2020/2. Here is the alter command to update the partition of the table sales.

hive> ALTER TABLE sales PARTITION(year = 2020, quarter = 2) SET LOCATION 'hdfs://user/svc_account/fixed_date/2020/2';

Drop a Hive partition

Let’s see a few variations of drop partition.

Drop a single partition

hive> ALTER TABLE sales DROP IF EXISTS PARTITION(year = 2020, quarter = 2);

Drop multiple partitions 

With the below alter script, we provide the exact partitions we would like to delete.

hive> ALTER TABLE sales drop if exists partition (year = 2020, quarter = 1), partition (year = 2020, quarter = 2);

Here is how we dynamically pick partitions to drop. Below script drops all partitions from sales table with year greater than 2019.

hive> ALTER TABLE sales drop partition (year > 2019);

 

Big Data In Real World
Big Data In Real World
We are a group of Big Data engineers who are passionate about Big Data and related Big Data technologies. We have designed, developed, deployed and maintained Big Data applications ranging from batch to real time streaming big data platforms. We have seen a wide range of real world big data problems, implemented some innovative and complex (or simple, depending on how you look at it) solutions.

Comments are closed.

How to update or drop a Hive Partition?
This website uses cookies to improve your experience. By using this website you agree to our Data Protection Policy.

Hadoop In Real World is now Big Data In Real World!

X