Index: ql/src/test/results/clientpositive/drop_partitions_ignore_protection.q.out =================================================================== --- ql/src/test/results/clientpositive/drop_partitions_ignore_protection.q.out (revision 0) +++ ql/src/test/results/clientpositive/drop_partitions_ignore_protection.q.out (working copy) @@ -0,0 +1,46 @@ +PREHOOK: query: create table tbl_protectmode_no_drop (c1 string,c2 string) partitioned by (p string) +PREHOOK: type: CREATETABLE +POSTHOOK: query: create table tbl_protectmode_no_drop (c1 string,c2 string) partitioned by (p string) +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: default@tbl_protectmode_no_drop +PREHOOK: query: alter table tbl_protectmode_no_drop add partition (p='p1') +PREHOOK: type: ALTERTABLE_ADDPARTS +PREHOOK: Input: default@tbl_protectmode_no_drop +POSTHOOK: query: alter table tbl_protectmode_no_drop add partition (p='p1') +POSTHOOK: type: ALTERTABLE_ADDPARTS +POSTHOOK: Input: default@tbl_protectmode_no_drop +POSTHOOK: Output: default@tbl_protectmode_no_drop@p=p1 +PREHOOK: query: alter table tbl_protectmode_no_drop partition (p='p1') enable no_drop +PREHOOK: type: ALTERPARTITION_PROTECTMODE +PREHOOK: Input: default@tbl_protectmode_no_drop +PREHOOK: Output: default@tbl_protectmode_no_drop@p=p1 +POSTHOOK: query: alter table tbl_protectmode_no_drop partition (p='p1') enable no_drop +POSTHOOK: type: ALTERPARTITION_PROTECTMODE +POSTHOOK: Input: default@tbl_protectmode_no_drop +POSTHOOK: Input: default@tbl_protectmode_no_drop@p=p1 +POSTHOOK: Output: default@tbl_protectmode_no_drop@p=p1 +PREHOOK: query: desc extended tbl_protectmode_no_drop partition (p='p1') +PREHOOK: type: DESCTABLE +POSTHOOK: query: desc extended tbl_protectmode_no_drop partition (p='p1') +POSTHOOK: type: DESCTABLE +c1 string +c2 string +p string + +#### A masked pattern was here #### +PREHOOK: query: alter table tbl_protectmode_no_drop drop partition (p='p1') ignore protection +PREHOOK: type: ALTERTABLE_DROPPARTS +PREHOOK: Input: default@tbl_protectmode_no_drop +PREHOOK: Output: default@tbl_protectmode_no_drop@p=p1 +POSTHOOK: query: alter table tbl_protectmode_no_drop drop partition (p='p1') ignore protection +POSTHOOK: type: ALTERTABLE_DROPPARTS +POSTHOOK: Input: default@tbl_protectmode_no_drop +POSTHOOK: Output: default@tbl_protectmode_no_drop@p=p1 +PREHOOK: query: drop table tbl_protectmode_no_drop +PREHOOK: type: DROPTABLE +PREHOOK: Input: default@tbl_protectmode_no_drop +PREHOOK: Output: default@tbl_protectmode_no_drop +POSTHOOK: query: drop table tbl_protectmode_no_drop +POSTHOOK: type: DROPTABLE +POSTHOOK: Input: default@tbl_protectmode_no_drop +POSTHOOK: Output: default@tbl_protectmode_no_drop Index: ql/src/test/queries/clientpositive/drop_partitions_ignore_protection.q =================================================================== --- ql/src/test/queries/clientpositive/drop_partitions_ignore_protection.q (revision 0) +++ ql/src/test/queries/clientpositive/drop_partitions_ignore_protection.q (working copy) @@ -0,0 +1,10 @@ +create table tbl_protectmode_no_drop (c1 string,c2 string) partitioned by (p string); +alter table tbl_protectmode_no_drop add partition (p='p1'); +alter table tbl_protectmode_no_drop partition (p='p1') enable no_drop; +desc extended tbl_protectmode_no_drop partition (p='p1'); + +### The partition will be dropped, even though we have enabled no_drop ### +### as 'ignore protection' has been specified in the command predicate ### +alter table tbl_protectmode_no_drop drop partition (p='p1') ignore protection; +drop table tbl_protectmode_no_drop; + Index: ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java (revision 1403549) +++ ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java (working copy) @@ -3356,18 +3356,20 @@ break; } } - for (Partition p : partitions) { - if (!p.canDrop()) { - throw new HiveException("Table " + tbl.getTableName() - + " Partition " + p.getName() - + " is protected from being dropped"); - } else if (ArchiveUtils.isArchived(p)) { - int partAchiveLevel = ArchiveUtils.getArchivingLevel(p); - // trying to drop partitions inside a har, disallow it. - if (partAchiveLevel < partPrefixToDrop) { - throw new HiveException( - "Cannot drop a subset of partitions in an archive, partition " - + p.getName()); + if (!dropTbl.getIgnoreProtection()) { + for (Partition p : partitions) { + if (!p.canDrop()) { + throw new HiveException("Table " + tbl.getTableName() + + " Partition " + p.getName() + + " is protected from being dropped"); + } else if (ArchiveUtils.isArchived(p)) { + int partAchiveLevel = ArchiveUtils.getArchivingLevel(p); + // trying to drop partitions inside a har, disallow it. + if (partAchiveLevel < partPrefixToDrop) { + throw new HiveException( + "Cannot drop a subset of partitions in an archive, partition " + + p.getName()); + } } } } Index: ql/src/java/org/apache/hadoop/hive/ql/plan/DropTableDesc.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/plan/DropTableDesc.java (revision 1403549) +++ ql/src/java/org/apache/hadoop/hive/ql/plan/DropTableDesc.java (working copy) @@ -34,6 +34,7 @@ ArrayList partSpecs; boolean expectView; boolean ifExists; + boolean ignoreProtection; boolean stringPartitionColumns; // This is due to JDO not working very well with // non-string partition columns. // We need a different codepath for them @@ -50,17 +51,20 @@ partSpecs = null; this.expectView = expectView; this.ifExists = ifExists; + this.ignoreProtection = false; this.stringPartitionColumns = stringPartitionColumns; } public DropTableDesc(String tableName, List partSpecs, - boolean expectView, boolean stringPartitionColumns) { + boolean expectView, boolean stringPartitionColumns, + boolean ignoreProtection) { this.tableName = tableName; this.partSpecs = new ArrayList(partSpecs.size()); for (int i = 0; i < partSpecs.size(); i++) { this.partSpecs.add(partSpecs.get(i)); } + this.ignoreProtection = ignoreProtection; this.expectView = expectView; this.stringPartitionColumns = stringPartitionColumns; } @@ -97,6 +101,21 @@ } /** + * @return whether or not protection will be ignored for the partition + */ + public boolean getIgnoreProtection() { + return ignoreProtection; + } + + /** + * @param ignoreProtection + * set whether or not protection will be ignored for the partition + */ + public void setIgnoreProtection(boolean ignoreProtection) { + this.ignoreProtection = ignoreProtection; + } + + /** * @return whether to expect a view being dropped */ public boolean getExpectView() { Index: ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g (revision 1403549) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/Hive.g (working copy) @@ -266,6 +266,7 @@ TOK_TABCOLVALUE; TOK_TABCOLVALUE_PAIR; TOK_TABCOLVALUES; +TOK_IGNOREPROTECTION; } @@ -392,6 +393,12 @@ -> ^(TOK_ORREPLACE) ; +ignoreProtection +@init { msgs.push("ignore protection clause"); } +@after { msgs.pop(); } + : KW_IGNORE KW_PROTECTION + -> ^(TOK_IGNOREPROTECTION) + ; createDatabaseStatement @init { msgs.push("create database statement"); } @@ -698,8 +705,8 @@ alterStatementSuffixDropPartitions @init { msgs.push("drop partition statement"); } @after { msgs.pop(); } - : Identifier KW_DROP ifExists? dropPartitionSpec (COMMA dropPartitionSpec)* - -> ^(TOK_ALTERTABLE_DROPPARTS Identifier dropPartitionSpec+ ifExists?) + : Identifier KW_DROP ifExists? dropPartitionSpec (COMMA dropPartitionSpec)* ignoreProtection? + -> ^(TOK_ALTERTABLE_DROPPARTS Identifier dropPartitionSpec+ ifExists? ignoreProtection?) ; alterStatementSuffixProperties @@ -2297,6 +2304,8 @@ KW_DESCRIBE: 'DESCRIBE'; KW_DROP: 'DROP'; KW_RENAME: 'RENAME'; +KW_IGNORE: 'IGNORE'; +KW_PROTECTION: 'PROTECTION'; KW_TO: 'TO'; KW_COMMENT: 'COMMENT'; KW_BOOLEAN: 'BOOLEAN'; Index: ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java (revision 1403549) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java (working copy) @@ -2000,9 +2000,9 @@ !ifExists && !HiveConf.getBoolVar(conf, ConfVars.DROPIGNORESNONEXISTENT); addTableDropPartsOutputs(tblName, partSpecs, throwException, stringPartitionColumns); } - + boolean ignoreProtection = (ast.getFirstChildWithType(HiveParser.TOK_IGNOREPROTECTION) != null); DropTableDesc dropTblDesc = - new DropTableDesc(tblName, partSpecs, expectView, stringPartitionColumns); + new DropTableDesc(tblName, partSpecs, expectView, stringPartitionColumns, ignoreProtection); rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), dropTblDesc), conf));