diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java index 372cfad866..d7aae78bf6 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java @@ -779,7 +779,7 @@ private static void generateConstraintInfos(ASTNode child, List columnNa } else if (type == HiveParser.TOK_ENABLE) { enable = true; // validate is true by default if we enable the constraint - validate = true; + validate = false; } else if (type == HiveParser.TOK_DISABLE) { enable = false; // validate is false by default if we disable the constraint @@ -792,11 +792,6 @@ private static void generateConstraintInfos(ASTNode child, List columnNa rely = true; } } - if (enable) { - throw new SemanticException( - ErrorMsg.INVALID_CSTR_SYNTAX.getMsg("ENABLE/ENFORCED feature not supported yet. " - + "Please use DISABLE/NOT ENFORCED instead.")); - } if (validate) { throw new SemanticException( ErrorMsg.INVALID_CSTR_SYNTAX.getMsg("VALIDATE feature not supported yet. " diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index dbf9363d11..a0554d661d 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -12116,6 +12116,33 @@ private void validate(Task task, boolean reworkMapredWor return retValue; } + private boolean hasEnabledConstraints(List primaryKeys, + List foreignKeys, + List uniqueConstraints, + List notNullConstraints){ + for(SQLPrimaryKey constr:primaryKeys){ + if(constr.isEnable_cstr() || constr.isValidate_cstr()){ + return true; + } + } + for(SQLForeignKey constr:foreignKeys){ + if(constr.isEnable_cstr() || constr.isValidate_cstr()){ + return true; + } + } + for(SQLUniqueConstraint constr:uniqueConstraints){ + if(constr.isEnable_cstr() || constr.isValidate_cstr()) { + return true; + } + } + for(SQLNotNullConstraint nnC:notNullConstraints){ + if(nnC.isEnable_cstr() || nnC.isValidate_cstr()){ + return true; + } + } + return false; + } + /** * Analyze the create table command. If it is a regular create-table or * create-table-like statements, we create a DDLWork and return true. If it is @@ -12295,6 +12322,14 @@ ASTNode analyzeCreateTable( throw new SemanticException("Unrecognized command."); } + if(isExt && hasEnabledConstraints(primaryKeys, foreignKeys, uniqueConstraints, + notNullConstraints)){ + throw new SemanticException( + ErrorMsg.INVALID_CSTR_SYNTAX.getMsg("Constraints are disallowed with External tables. " + + "Only RELY is allowed.")); + } + + storageFormat.fillDefaultStorageFormat(isExt, false); // check for existence of table