Tuesday, June 12, 2018

Hive: how to set tables read-only and DROP them

Set table read-only: PROTECT_MODE = NO_DROP


--- Set table read-only ---
ALTER TABLE testdb.sometable  SET TBLPROPERTIES ('PROTECT_MODE' = 'NO_DROP');
 
--- Attempt to drop read-only table  ---
hive (TESTDB)> DROP TABLE testdb.sometable;
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Table testdb.sometable is protected from being dropped

DROP read-only tables: PROTECT_MODE = NONE


--- Unset table read-only ---
ALTER TABLE testdb.sometable  SET TBLPROPERTIES ('PROTECT_MODE' = 'NONE');
 
--- Then drop to bypass .Trash ---
hive (TESTDB)> DROP TABLE testdb.sometable PURGE;
OK
Time taken: 0.067 seconds

No comments:

Post a Comment