We can safeguard the table and table partition from being dropped mistakenly by using the NO DROP keyword, as indicated in the previous article. Data protection can be configured at the table or partition level. When NO DROP is enabled, a table will not be dropped. The data in a table or partition cannot be queried while OFFLINE is enabled, but the metadata can still be viewed.
The table cannot be dropped if any partition in the table has NO DROP enabled. Partitions can be dropped if a table has NO DROP enabled, however NO DROP CASCADE partitions cannot be dropped unless the drop partition command includes IGNORE PROTECTION.
Please note that IGNORE PROTECTION is not available in version 2.0.0 and later. It is replaced by PURGE.
ALTER TABLE table_name DROP [IF EXISTS] PARTITION partition_spec IGNORE PROTECTION;
Please click here for sample data and table structure for the below table.
Enabling the NO_DROP
hive> ALTER TABLE TownsList_Dynamic ENABLE NO_DROP CASCADE;
If we try to drop the table or any specific partition we will receive an error.
hive> ALTER TABLE TownsList_Dynamic DROP PARTITION (country=’Scotland’);
FAILED: SemanticException [Error 30011]: Partition protected from being dropped default@townslist_dynamic@country=Scotland
hive> DROP TABLE TownsList_Dynamic;
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Table townslist_dynamic is protected from being dropped.
So, we will use IGNORE PROTECTION to see how it works.
Hive> ALTER TABLE TownsList_Dynamic DROP PARTITION (country=’England’) IGNORE PROTECTION;
Now, this is executed successfully without any errors.
Please read –
Protect the table from being dropped.
Disable querying the table in Hive.
Protect the table partition from being dropped.
Disable querying the table partition in Hive.