HIVE-16604: Use [NOT] ENFORCED for column constraint characteristics (Jesus 
Camacho Rodriguez, 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/abcadab7
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/abcadab7
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/abcadab7

Branch: refs/heads/master
Commit: abcadab7c219c1458bdcab7a9379a928e3ea9305
Parents: c4c7568
Author: Jesus Camacho Rodriguez <jcama...@apache.org>
Authored: Wed Oct 18 14:49:34 2017 -0700
Committer: Jesus Camacho Rodriguez <jcama...@apache.org>
Committed: Thu Oct 19 11:06:27 2017 -0700

----------------------------------------------------------------------
 .../hive/ql/parse/BaseSemanticAnalyzer.java     |   4 +-
 .../org/apache/hadoop/hive/ql/parse/HiveLexer.g |   1 +
 .../apache/hadoop/hive/ql/parse/HiveParser.g    |   8 ++
 .../hadoop/hive/ql/parse/IdentifiersParser.g    |   2 +-
 .../create_with_constraints_enforced.q          |   1 +
 .../clientpositive/create_with_constraints2.q   |   8 ++
 .../create_with_constraints_enable.q.out        |   2 +-
 .../create_with_constraints_enforced.q.out      |   1 +
 .../create_with_constraints2.q.out              | 120 +++++++++++++++++++
 9 files changed, 143 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/abcadab7/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 50a55d8..3efeecd 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
@@ -793,8 +793,8 @@ public abstract class BaseSemanticAnalyzer {
     }
     if (enable) {
       throw new SemanticException(
-          ErrorMsg.INVALID_CSTR_SYNTAX.getMsg("ENABLE feature not supported 
yet. "
-              + "Please use DISABLE instead."));
+          ErrorMsg.INVALID_CSTR_SYNTAX.getMsg("ENABLE/ENFORCED feature not 
supported yet. "
+              + "Please use DISABLE/NOT ENFORCED instead."));
     }
     if (validate) {
       throw new SemanticException(

http://git-wip-us.apache.org/repos/asf/hive/blob/abcadab7/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveLexer.g
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveLexer.g 
b/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveLexer.g
index d0ce4ae..74f9d95 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveLexer.g
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveLexer.g
@@ -332,6 +332,7 @@ KW_PRIMARY: 'PRIMARY';
 KW_FOREIGN: 'FOREIGN';
 KW_REFERENCES: 'REFERENCES';
 KW_CONSTRAINT: 'CONSTRAINT';
+KW_ENFORCED: 'ENFORCED';
 KW_VALIDATE: 'VALIDATE';
 KW_NOVALIDATE: 'NOVALIDATE';
 KW_RELY: 'RELY';

http://git-wip-us.apache.org/repos/asf/hive/blob/abcadab7/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g 
b/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
index c2d8904..a2e55ed 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
@@ -2190,6 +2190,7 @@ enableValidateSpecification
 @init { pushMsg("enable specification", state); }
 @after { popMsg(state); }
     : enableSpecification validateSpecification?
+    | enforcedSpecification
     ;
 
 enableSpecification
@@ -2206,6 +2207,13 @@ validateSpecification
     | KW_NOVALIDATE -> ^(TOK_NOVALIDATE)
     ;
 
+enforcedSpecification
+@init { pushMsg("enforced specification", state); }
+@after { popMsg(state); }
+    : KW_ENFORCED -> ^(TOK_ENABLE)
+    | KW_NOT KW_ENFORCED -> ^(TOK_DISABLE)
+    ;
+
 relySpecification
 @init { pushMsg("rely specification", state); }
 @after { popMsg(state); }

http://git-wip-us.apache.org/repos/asf/hive/blob/abcadab7/ql/src/java/org/apache/hadoop/hive/ql/parse/IdentifiersParser.g
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/IdentifiersParser.g 
b/ql/src/java/org/apache/hadoop/hive/ql/parse/IdentifiersParser.g
index 0a7b7b2..69a1d63 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/IdentifiersParser.g
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/IdentifiersParser.g
@@ -793,7 +793,7 @@ nonReserved
     | KW_COMMENT | KW_COMPACT | KW_COMPACTIONS | KW_COMPUTE | KW_CONCATENATE | 
KW_CONTINUE | KW_DATA | KW_DAY
     | KW_DATABASES | KW_DATETIME | KW_DBPROPERTIES | KW_DEFERRED | KW_DEFINED 
| KW_DELIMITED | KW_DEPENDENCY 
     | KW_DESC | KW_DIRECTORIES | KW_DIRECTORY | KW_DISABLE | KW_DISTRIBUTE | 
KW_DOW | KW_ELEM_TYPE 
-    | KW_ENABLE | KW_ESCAPED | KW_EXCLUSIVE | KW_EXPLAIN | KW_EXPORT | 
KW_FIELDS | KW_FILE | KW_FILEFORMAT
+    | KW_ENABLE | KW_ENFORCED | KW_ESCAPED | KW_EXCLUSIVE | KW_EXPLAIN | 
KW_EXPORT | KW_FIELDS | KW_FILE | KW_FILEFORMAT
     | KW_FIRST | KW_FORMAT | KW_FORMATTED | KW_FUNCTIONS | KW_HOLD_DDLTIME | 
KW_HOUR | KW_IDXPROPERTIES | KW_IGNORE
     | KW_INDEX | KW_INDEXES | KW_INPATH | KW_INPUTDRIVER | KW_INPUTFORMAT | 
KW_ITEMS | KW_JAR | KW_KILL
     | KW_KEYS | KW_KEY_TYPE | KW_LAST | KW_LIMIT | KW_OFFSET | KW_LINES | 
KW_LOAD | KW_LOCATION | KW_LOCK | KW_LOCKS | KW_LOGICAL | KW_LONG

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

http://git-wip-us.apache.org/repos/asf/hive/blob/abcadab7/ql/src/test/queries/clientpositive/create_with_constraints2.q
----------------------------------------------------------------------
diff --git a/ql/src/test/queries/clientpositive/create_with_constraints2.q 
b/ql/src/test/queries/clientpositive/create_with_constraints2.q
new file mode 100644
index 0000000..22ea23d
--- /dev/null
+++ b/ql/src/test/queries/clientpositive/create_with_constraints2.q
@@ -0,0 +1,8 @@
+CREATE TABLE table1 (a STRING, b STRING, PRIMARY KEY (a) NOT ENFORCED);
+CREATE TABLE table2 (a STRING, b STRING, PRIMARY KEY (a) NOT ENFORCED RELY);
+
+DESCRIBE EXTENDED table1;
+DESCRIBE EXTENDED table2;
+
+DESCRIBE FORMATTED table1;
+DESCRIBE FORMATTED table2;

http://git-wip-us.apache.org/repos/asf/hive/blob/abcadab7/ql/src/test/results/clientnegative/create_with_constraints_enable.q.out
----------------------------------------------------------------------
diff --git 
a/ql/src/test/results/clientnegative/create_with_constraints_enable.q.out 
b/ql/src/test/results/clientnegative/create_with_constraints_enable.q.out
index 65d3bfe..2b24412 100644
--- a/ql/src/test/results/clientnegative/create_with_constraints_enable.q.out
+++ b/ql/src/test/results/clientnegative/create_with_constraints_enable.q.out
@@ -1 +1 @@
-FAILED: SemanticException [Error 10326]: Invalid Constraint syntax ENABLE 
feature not supported yet. Please use DISABLE instead.
+FAILED: SemanticException [Error 10326]: Invalid Constraint syntax 
ENABLE/ENFORCED feature not supported yet. Please use DISABLE/NOT ENFORCED 
instead.

http://git-wip-us.apache.org/repos/asf/hive/blob/abcadab7/ql/src/test/results/clientnegative/create_with_constraints_enforced.q.out
----------------------------------------------------------------------
diff --git 
a/ql/src/test/results/clientnegative/create_with_constraints_enforced.q.out 
b/ql/src/test/results/clientnegative/create_with_constraints_enforced.q.out
new file mode 100644
index 0000000..2b24412
--- /dev/null
+++ b/ql/src/test/results/clientnegative/create_with_constraints_enforced.q.out
@@ -0,0 +1 @@
+FAILED: SemanticException [Error 10326]: Invalid Constraint syntax 
ENABLE/ENFORCED feature not supported yet. Please use DISABLE/NOT ENFORCED 
instead.

http://git-wip-us.apache.org/repos/asf/hive/blob/abcadab7/ql/src/test/results/clientpositive/create_with_constraints2.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/create_with_constraints2.q.out 
b/ql/src/test/results/clientpositive/create_with_constraints2.q.out
new file mode 100644
index 0000000..eea74d9
--- /dev/null
+++ b/ql/src/test/results/clientpositive/create_with_constraints2.q.out
@@ -0,0 +1,120 @@
+PREHOOK: query: CREATE TABLE table1 (a STRING, b STRING, PRIMARY KEY (a) NOT 
ENFORCED)
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@table1
+POSTHOOK: query: CREATE TABLE table1 (a STRING, b STRING, PRIMARY KEY (a) NOT 
ENFORCED)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@table1
+PREHOOK: query: CREATE TABLE table2 (a STRING, b STRING, PRIMARY KEY (a) NOT 
ENFORCED RELY)
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@table2
+POSTHOOK: query: CREATE TABLE table2 (a STRING, b STRING, PRIMARY KEY (a) NOT 
ENFORCED RELY)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@table2
+PREHOOK: query: DESCRIBE EXTENDED table1
+PREHOOK: type: DESCTABLE
+PREHOOK: Input: default@table1
+POSTHOOK: query: DESCRIBE EXTENDED table1
+POSTHOOK: type: DESCTABLE
+POSTHOOK: Input: default@table1
+a                      string                                      
+b                      string                                      
+                
+#### A masked pattern was here ####
+Constraints    Primary Key for default.table1:[a], Constraint Name: #### A 
masked pattern was here ####         
+PREHOOK: query: DESCRIBE EXTENDED table2
+PREHOOK: type: DESCTABLE
+PREHOOK: Input: default@table2
+POSTHOOK: query: DESCRIBE EXTENDED table2
+POSTHOOK: type: DESCTABLE
+POSTHOOK: Input: default@table2
+a                      string                                      
+b                      string                                      
+                
+#### A masked pattern was here ####
+Constraints    Primary Key for default.table2:[a], Constraint Name: #### A 
masked pattern was here ####         
+PREHOOK: query: DESCRIBE FORMATTED table1
+PREHOOK: type: DESCTABLE
+PREHOOK: Input: default@table1
+POSTHOOK: query: DESCRIBE FORMATTED table1
+POSTHOOK: type: DESCTABLE
+POSTHOOK: Input: default@table1
+# col_name             data_type               comment             
+a                      string                                      
+b                      string                                      
+                
+# Detailed Table Information            
+Database:              default                  
+#### A masked pattern was here ####
+Retention:             0                        
+#### A masked pattern was here ####
+Table Type:            MANAGED_TABLE            
+Table Parameters:               
+       COLUMN_STATS_ACCURATE   
{\"BASIC_STATS\":\"true\",\"COLUMN_STATS\":{\"a\":\"true\",\"b\":\"true\"}}
+       numFiles                0                   
+       numRows                 0                   
+       rawDataSize             0                   
+       totalSize               0                   
+#### A masked pattern was here ####
+                
+# Storage Information           
+SerDe Library:         org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe      
 
+InputFormat:           org.apache.hadoop.mapred.TextInputFormat         
+OutputFormat:          
org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat       
+Compressed:            No                       
+Num Buckets:           -1                       
+Bucket Columns:        []                       
+Sort Columns:          []                       
+Storage Desc Params:            
+       serialization.format    1                   
+                
+# Constraints           
+                
+# Primary Key           
+Table:                 default.table1           
+Constraint Name:       #### A masked pattern was here ####      
+Column Names:          a                        
+PREHOOK: query: DESCRIBE FORMATTED table2
+PREHOOK: type: DESCTABLE
+PREHOOK: Input: default@table2
+POSTHOOK: query: DESCRIBE FORMATTED table2
+POSTHOOK: type: DESCTABLE
+POSTHOOK: Input: default@table2
+# col_name             data_type               comment             
+a                      string                                      
+b                      string                                      
+                
+# Detailed Table Information            
+Database:              default                  
+#### A masked pattern was here ####
+Retention:             0                        
+#### A masked pattern was here ####
+Table Type:            MANAGED_TABLE            
+Table Parameters:               
+       COLUMN_STATS_ACCURATE   
{\"BASIC_STATS\":\"true\",\"COLUMN_STATS\":{\"a\":\"true\",\"b\":\"true\"}}
+       numFiles                0                   
+       numRows                 0                   
+       rawDataSize             0                   
+       totalSize               0                   
+#### A masked pattern was here ####
+                
+# Storage Information           
+SerDe Library:         org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe      
 
+InputFormat:           org.apache.hadoop.mapred.TextInputFormat         
+OutputFormat:          
org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat       
+Compressed:            No                       
+Num Buckets:           -1                       
+Bucket Columns:        []                       
+Sort Columns:          []                       
+Storage Desc Params:            
+       serialization.format    1                   
+                
+# Constraints           
+                
+# Primary Key           
+Table:                 default.table2           
+Constraint Name:       #### A masked pattern was here ####      
+Column Names:          a                        

Reply via email to