hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vg...@apache.org
Subject hive git commit: HIVE-18598: Disallow NOT NULL constraints to be ENABLED/ENFORCED with EXTERNAL table(Vineet Garg, reviewed by Ashutosh Chauhan)
Date Mon, 12 Feb 2018 18:55:25 GMT
Repository: hive
Updated Branches:
  refs/heads/master 887233d28 -> fa14a4365


HIVE-18598: Disallow NOT NULL constraints to be ENABLED/ENFORCED with EXTERNAL table(Vineet
Garg, reviewed by Ashutosh Chauhan)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/fa14a436
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/fa14a436
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/fa14a436

Branch: refs/heads/master
Commit: fa14a436555d132fdab42e284538c19444f83b8c
Parents: 887233d
Author: Vineet Garg <vgarg@apache.org>
Authored: Mon Feb 12 10:54:37 2018 -0800
Committer: Vineet Garg <vgarg@apache.org>
Committed: Mon Feb 12 10:54:37 2018 -0800

----------------------------------------------------------------------
 .../hive/ql/parse/BaseSemanticAnalyzer.java     | 11 ++++++
 .../hive/ql/parse/DDLSemanticAnalyzer.java      | 40 +++++++++++++++++++-
 .../hadoop/hive/ql/parse/SemanticAnalyzer.java  |  7 ++++
 .../alter_external_with_constraint.q            |  3 ++
 .../alter_tableprops_external_with_constraint.q |  3 ++
 .../create_external_with_constraint.q           |  1 +
 .../alter_external_with_constraint.q.out        |  9 +++++
 ...er_tableprops_external_with_constraint.q.out |  9 +++++
 .../create_external_with_constraint.q.out       |  1 +
 9 files changed, 83 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/fa14a436/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java
----------------------------------------------------------------------
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 8a1bfd2..d18dba5 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
@@ -906,6 +906,17 @@ public abstract class BaseSemanticAnalyzer {
     }
   }
 
+  protected boolean hasEnabledOrValidatedConstraints(List<SQLNotNullConstraint> notNullConstraints){
+    if(notNullConstraints != null) {
+      for (SQLNotNullConstraint nnC : notNullConstraints) {
+        if (nnC.isEnable_cstr() || nnC.isValidate_cstr()) {
+          return true;
+        }
+      }
+    }
+    return false;
+  }
+
   private static void checkColumnName(String columnName) throws SemanticException {
     if (VirtualColumn.VIRTUAL_COLUMN_NAMES.contains(columnName.toUpperCase())) {
       throw new SemanticException(ErrorMsg.INVALID_COLUMN_NAME.getMsg(columnName));

http://git-wip-us.apache.org/repos/asf/hive/blob/fa14a436/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
index b766791..834cb0c 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
@@ -96,6 +96,7 @@ import org.apache.hadoop.hive.ql.metadata.Hive;
 import org.apache.hadoop.hive.ql.metadata.HiveException;
 import org.apache.hadoop.hive.ql.metadata.HiveUtils;
 import org.apache.hadoop.hive.ql.metadata.InvalidTableException;
+import org.apache.hadoop.hive.ql.metadata.NotNullConstraint;
 import org.apache.hadoop.hive.ql.metadata.Partition;
 import org.apache.hadoop.hive.ql.metadata.Table;
 import org.apache.hadoop.hive.ql.parse.authorization.AuthorizationParseUtils;
@@ -1895,6 +1896,26 @@ public class DDLSemanticAnalyzer extends BaseSemanticAnalyzer {
     }
   }
 
+  private boolean hasConstraintsEnabled(final String tblName) throws SemanticException{
+
+    NotNullConstraint nnc = null;
+    try {
+      // retrieve enabled NOT NULL constraint from metastore
+      nnc = Hive.get().getEnabledNotNullConstraints(
+          db.getDatabaseCurrent().getName(), tblName);
+    } catch (Exception e) {
+      if (e instanceof SemanticException) {
+        throw (SemanticException) e;
+      } else {
+        throw (new RuntimeException(e));
+      }
+    }
+    if(nnc != null  && !nnc.getNotNullConstraints().isEmpty()) {
+      return true;
+    }
+    return false;
+  }
+
   private void analyzeAlterTableProps(String[] qualified, HashMap<String, String> partSpec,
       ASTNode ast, boolean expectView, boolean isUnset) throws SemanticException {
 
@@ -1919,7 +1940,17 @@ public class DDLSemanticAnalyzer extends BaseSemanticAnalyzer {
           throw new SemanticException("AlterTable " + entry.getKey() + " failed with value
"
               + entry.getValue());
         }
-      } else {
+      }
+      // if table is being modified to be external we need to make sure existing table
+      // doesn't have enabled constraint since constraints are disallowed with such tables
+      else if(entry.getKey().equals("external") && entry.getValue().equals("true")){
+        if(hasConstraintsEnabled(qualified[1])){
+          throw new SemanticException(
+              ErrorMsg.INVALID_CSTR_SYNTAX.getMsg("Table: " + tableName + " has constraints
enabled."
+                  + "Please remove those constraints to change this property."));
+        }
+      }
+      else {
         if (queryState.getCommandType()
             .equals(HiveOperation.ALTERTABLE_UPDATETABLESTATS.getOperationName())
             || queryState.getCommandType()
@@ -3354,6 +3385,13 @@ public class DDLSemanticAnalyzer extends BaseSemanticAnalyzer {
     /* Validate the operation of renaming a column name. */
     Table tab = getTable(qualified);
 
+    if(tab.getTableType() == TableType.EXTERNAL_TABLE
+        && hasEnabledOrValidatedConstraints(notNullConstraints)){
+      throw new SemanticException(
+          ErrorMsg.INVALID_CSTR_SYNTAX.getMsg("Constraints are disallowed with External tables.
"
+              + "Only RELY is allowed."));
+    }
+
     SkewedInfo skewInfo = tab.getTTable().getSd().getSkewedInfo();
     if ((null != skewInfo)
         && (null != skewInfo.getSkewedColNames())

http://git-wip-us.apache.org/repos/asf/hive/blob/fa14a436/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
----------------------------------------------------------------------
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 5c96653..3e9c238 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
@@ -12554,6 +12554,13 @@ public class SemanticAnalyzer extends BaseSemanticAnalyzer {
       throw new SemanticException("Unrecognized command.");
     }
 
+    if(isExt && hasEnabledOrValidatedConstraints(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

http://git-wip-us.apache.org/repos/asf/hive/blob/fa14a436/ql/src/test/queries/clientnegative/alter_external_with_constraint.q
----------------------------------------------------------------------
diff --git a/ql/src/test/queries/clientnegative/alter_external_with_constraint.q b/ql/src/test/queries/clientnegative/alter_external_with_constraint.q
new file mode 100644
index 0000000..041585e
--- /dev/null
+++ b/ql/src/test/queries/clientnegative/alter_external_with_constraint.q
@@ -0,0 +1,3 @@
+CREATE external TABLE table1 (a STRING, b STRING); 
+Alter table table1 change b b STRING NOT NULL enable;
+

http://git-wip-us.apache.org/repos/asf/hive/blob/fa14a436/ql/src/test/queries/clientnegative/alter_tableprops_external_with_constraint.q
----------------------------------------------------------------------
diff --git a/ql/src/test/queries/clientnegative/alter_tableprops_external_with_constraint.q
b/ql/src/test/queries/clientnegative/alter_tableprops_external_with_constraint.q
new file mode 100644
index 0000000..9deefb1
--- /dev/null
+++ b/ql/src/test/queries/clientnegative/alter_tableprops_external_with_constraint.q
@@ -0,0 +1,3 @@
+CREATE TABLE table1 (a STRING NOT NULL enforced, b STRING); 
+Alter table table1 set TBLPROPERTIES('external'='true');
+

http://git-wip-us.apache.org/repos/asf/hive/blob/fa14a436/ql/src/test/queries/clientnegative/create_external_with_constraint.q
----------------------------------------------------------------------
diff --git a/ql/src/test/queries/clientnegative/create_external_with_constraint.q b/ql/src/test/queries/clientnegative/create_external_with_constraint.q
new file mode 100644
index 0000000..5b12662
--- /dev/null
+++ b/ql/src/test/queries/clientnegative/create_external_with_constraint.q
@@ -0,0 +1 @@
+CREATE external TABLE table1 (a STRING not null enforced, b STRING); 

http://git-wip-us.apache.org/repos/asf/hive/blob/fa14a436/ql/src/test/results/clientnegative/alter_external_with_constraint.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientnegative/alter_external_with_constraint.q.out b/ql/src/test/results/clientnegative/alter_external_with_constraint.q.out
new file mode 100644
index 0000000..a6001a4
--- /dev/null
+++ b/ql/src/test/results/clientnegative/alter_external_with_constraint.q.out
@@ -0,0 +1,9 @@
+PREHOOK: query: CREATE external TABLE table1 (a STRING, b STRING)
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@table1
+POSTHOOK: query: CREATE external TABLE table1 (a STRING, b STRING)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@table1
+FAILED: SemanticException [Error 10326]: Invalid Constraint syntax Constraints are disallowed
with External tables. Only RELY is allowed.

http://git-wip-us.apache.org/repos/asf/hive/blob/fa14a436/ql/src/test/results/clientnegative/alter_tableprops_external_with_constraint.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientnegative/alter_tableprops_external_with_constraint.q.out
b/ql/src/test/results/clientnegative/alter_tableprops_external_with_constraint.q.out
new file mode 100644
index 0000000..6cfc932
--- /dev/null
+++ b/ql/src/test/results/clientnegative/alter_tableprops_external_with_constraint.q.out
@@ -0,0 +1,9 @@
+PREHOOK: query: CREATE TABLE table1 (a STRING NOT NULL enforced, b STRING)
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@table1
+POSTHOOK: query: CREATE TABLE table1 (a STRING NOT NULL enforced, b STRING)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@table1
+FAILED: SemanticException [Error 10326]: Invalid Constraint syntax Table: default.table1
has constraints enabled.Please remove those constraints to change this property.

http://git-wip-us.apache.org/repos/asf/hive/blob/fa14a436/ql/src/test/results/clientnegative/create_external_with_constraint.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientnegative/create_external_with_constraint.q.out b/ql/src/test/results/clientnegative/create_external_with_constraint.q.out
new file mode 100644
index 0000000..e69566d
--- /dev/null
+++ b/ql/src/test/results/clientnegative/create_external_with_constraint.q.out
@@ -0,0 +1 @@
+FAILED: SemanticException [Error 10326]: Invalid Constraint syntax Constraints are disallowed
with External tables. Only RELY is allowed.


Mime
View raw message