The NO_DROP keyword can be used to safeguard table partitions in the same way as it can be used to prevent the table from being dropped.
There’s always the risk of accidentally dropping the table or table partition. In such circumstances, we lose all or part of the table data. We can recover a table and its data in most RDBMSs if we have a backup file, but we lose the table and its data if we don’t. We can use the NO DROP keyword in Apache Hive to prevent a table or table partition from being removed.
The sample data for this exercise can be obtained from here.
ALTER TABLE table_name [PARTITION partition_spec] ENABLE|DISABLE NO_DROP [CASCADE];
Hive> ALTER TABLE TownsList_Dynamic PARTITION (country=’England’) ENABLE NO_DROP;
Now, let’s issue the drop table statement.
Hive> DROP TABLE emp;
Now, this returns the error as we expected.
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask.Table emp is protected from being dropped.
Disabling the NO_DROP.
Hive> ALTER TABLE TownsList_Dynamic PARTITION (country=’England’) DISABLE NO_DROP;
Please keep reading the subsequent posts.
Subscribe to our mailing list to be notified of new articles.