- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
How to delete/drop a partition of an external table along with data
- Labels:
-
Apache Hive
Created on ‎01-24-2017 09:26 PM - edited ‎09-16-2022 03:57 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have an external table which is created with partitions and i would like to delete/drop few partition along with data as i no longer require it.
Appreciate any suggestions.
Created ‎01-27-2017 12:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Did you try to drop the partition using Hive query ? It should look like this :
ALTER TABLE <table_name> DROP PARTITION (<partition_col_name>='<value>');
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-DropPartitions
If it does not delete the data you will need to delete the directory of the partition (in HDFS) after deleting it using the Hive query.
Created on ‎01-12-2018 09:18 AM - edited ‎01-12-2018 09:19 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use PURGE option to delete data file as well along with partition mentadata but it works only in INTERNAL/MANAGED tables
ALTER TABLE table_name DROP [IF EXISTS] PARTITION partition_spec PURGE;
External Tables have a two step process to alterr table drop partition + removing file
ALTER TABLE table_name DROP [IF EXISTS] PARTITION partition_spec;
hadoop fs -rm -r <partition file path>
