diff --git hcatalog/core/src/main/java/org/apache/hive/hcatalog/cli/SemanticAnalysis/CreateTableHook.java hcatalog/core/src/main/java/org/apache/hive/hcatalog/cli/SemanticAnalysis/CreateTableHook.java index 8b69223..8f8ac8b 100644 --- hcatalog/core/src/main/java/org/apache/hive/hcatalog/cli/SemanticAnalysis/CreateTableHook.java +++ hcatalog/core/src/main/java/org/apache/hive/hcatalog/cli/SemanticAnalysis/CreateTableHook.java @@ -106,7 +106,7 @@ public ASTNode preAnalyze(HiveSemanticAnalyzerHookContext context, case HiveParser.TOK_TABLEPARTCOLS: List partCols = BaseSemanticAnalyzer - .getColumns((ASTNode) child.getChild(0), false); + .getColumns(child, false); for (FieldSchema fs : partCols) { if (!fs.getType().equalsIgnoreCase("string")) { throw new SemanticException( diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g index 8708f2a..ac95da9 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g +++ ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g @@ -2112,8 +2112,8 @@ tableComment tablePartition @init { pushMsg("table partition specification", state); } @after { popMsg(state); } - : KW_PARTITIONED KW_BY LPAREN columnNameTypeList RPAREN - -> ^(TOK_TABLEPARTCOLS columnNameTypeList) + : KW_PARTITIONED KW_BY LPAREN columnNameTypeConstraint (COMMA columnNameTypeConstraint)* RPAREN + -> ^(TOK_TABLEPARTCOLS columnNameTypeConstraint+) ; tableBuckets @@ -2280,8 +2280,9 @@ columnNameTypeList @after { popMsg(state); } : columnNameType (COMMA columnNameType)* -> ^(TOK_TABCOLLIST columnNameType+) ; + columnNameTypeOrConstraintList -@init { pushMsg("column name type list with PK and FK", state); } +@init { pushMsg("column name type and constraints list", state); } @after { popMsg(state); } : columnNameTypeOrConstraint (COMMA columnNameTypeOrConstraint)* -> ^(TOK_TABCOLLIST columnNameTypeOrConstraint+) ; diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index 68240f0..1de3dd7 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -12351,7 +12351,8 @@ ASTNode analyzeCreateTable( comment = unescapeSQLString(child.getChild(0).getText()); break; case HiveParser.TOK_TABLEPARTCOLS: - partCols = getColumns((ASTNode) child.getChild(0), false); + partCols = getColumns(child, false, primaryKeys, foreignKeys, + uniqueConstraints, notNullConstraints); break; case HiveParser.TOK_ALTERTABLE_BUCKETS: bucketCols = getColumnNames((ASTNode) child.getChild(0)); diff --git ql/src/test/queries/clientpositive/create_with_constraints.q ql/src/test/queries/clientpositive/create_with_constraints.q index a17ca9d..7b2594b 100644 --- ql/src/test/queries/clientpositive/create_with_constraints.q +++ ql/src/test/queries/clientpositive/create_with_constraints.q @@ -13,15 +13,15 @@ CREATE TABLE table10 (a STRING, b STRING, CONSTRAINT pk10 PRIMARY KEY (a) DISABL CREATE TABLE table11 (a STRING, b STRING, c STRING, CONSTRAINT pk11 PRIMARY KEY (a) DISABLE RELY, CONSTRAINT fk11_1 FOREIGN KEY (a, b) REFERENCES table9(a, b) DISABLE, CONSTRAINT fk11_2 FOREIGN KEY (c) REFERENCES table4(x) DISABLE); CREATE TABLE table12 (a STRING CONSTRAINT nn12_1 NOT NULL DISABLE NORELY, b STRING); -CREATE TABLE table13 (a STRING NOT NULL DISABLE RELY, b STRING); +CREATE TABLE table13 (b STRING) PARTITIONED BY (a STRING NOT NULL DISABLE RELY); CREATE TABLE table14 (a STRING CONSTRAINT nn14_1 NOT NULL DISABLE RELY, b STRING); CREATE TABLE table15 (a STRING REFERENCES table4(x) DISABLE, b STRING); CREATE TABLE table16 (a STRING CONSTRAINT nn16_1 REFERENCES table4(x) DISABLE RELY, b STRING); CREATE TABLE table17 (a STRING CONSTRAINT uk17_1 UNIQUE DISABLE RELY, b STRING); -CREATE TABLE table18 (a STRING, b STRING, CONSTRAINT uk18_1 UNIQUE (b) DISABLE RELY); +CREATE TABLE table18 (a STRING, CONSTRAINT uk18_1 UNIQUE (b) DISABLE RELY) PARTITIONED BY (b STRING); CREATE TABLE table19 (a STRING, b STRING, CONSTRAINT pk19_1 PRIMARY KEY (b) DISABLE RELY, CONSTRAINT fk19_2 FOREIGN KEY (a) REFERENCES table19(b) DISABLE RELY); CREATE TABLE table20 (a STRING, b STRING, CONSTRAINT uk20_1 UNIQUE (b) DISABLE RELY, CONSTRAINT fk20_2 FOREIGN KEY (a) REFERENCES table20(b) DISABLE RELY); -CREATE TABLE table21 (a STRING, b STRING, CONSTRAINT uk21_1 UNIQUE (a,b) DISABLE); +CREATE TABLE table21 (a STRING, CONSTRAINT uk21_1 UNIQUE (a,b) DISABLE) PARTITIONED BY (b STRING); CREATE TABLE table22 (a STRING, b STRING, CONSTRAINT fk22_1 FOREIGN KEY (a,b) REFERENCES table21(a,b) DISABLE); DESCRIBE EXTENDED table1; @@ -74,6 +74,7 @@ ALTER TABLE table2 DROP CONSTRAINT pk1; ALTER TABLE table3 DROP CONSTRAINT fk1; ALTER TABLE table4 DROP CONSTRAINT nn4_1; ALTER TABLE table6 DROP CONSTRAINT fk4; +ALTER TABLE table8 DROP CONSTRAINT pk8; ALTER TABLE table16 DROP CONSTRAINT nn16_1; ALTER TABLE table18 DROP CONSTRAINT uk18_1; @@ -81,6 +82,7 @@ DESCRIBE EXTENDED table2; DESCRIBE EXTENDED table3; DESCRIBE EXTENDED table4; DESCRIBE EXTENDED table6; +DESCRIBE EXTENDED table8; DESCRIBE EXTENDED table16; DESCRIBE EXTENDED table18; @@ -88,18 +90,21 @@ DESCRIBE FORMATTED table2; DESCRIBE FORMATTED table3; DESCRIBE FORMATTED table4; DESCRIBE FORMATTED table6; +DESCRIBE FORMATTED table8; DESCRIBE FORMATTED table16; DESCRIBE FORMATTED table18; ALTER TABLE table2 ADD CONSTRAINT pkt2 PRIMARY KEY (a) DISABLE NOVALIDATE; ALTER TABLE table3 ADD CONSTRAINT fk1 FOREIGN KEY (x) REFERENCES table2(a) DISABLE NOVALIDATE RELY; ALTER TABLE table6 ADD CONSTRAINT fk4 FOREIGN KEY (y) REFERENCES table1(a) DISABLE NOVALIDATE; +ALTER TABLE table8 ADD CONSTRAINT pk8_2 PRIMARY KEY (a, b) DISABLE NOVALIDATE RELY; ALTER TABLE table16 CHANGE a a STRING REFERENCES table4(x) DISABLE NOVALIDATE; ALTER TABLE table18 ADD CONSTRAINT uk18_2 UNIQUE (a, b) DISABLE NOVALIDATE; DESCRIBE FORMATTED table2; DESCRIBE FORMATTED table3; DESCRIBE FORMATTED table6; +DESCRIBE FORMATTED table8; DESCRIBE FORMATTED table16; DESCRIBE FORMATTED table18; @@ -130,3 +135,10 @@ ALTER TABLE DbConstraint.Table2 ADD CONSTRAINT Pk1 PRIMARY KEY (a) DISABLE NOVAL DESCRIBE FORMATTED DbConstraint.Table2; ALTER TABLE DbConstraint.Table2 ADD CONSTRAINT fkx FOREIGN KEY (b) REFERENCES table1(a) DISABLE NOVALIDATE; DESCRIBE FORMATTED DbConstraint.Table2; + +CREATE TABLE table23 (a STRING) PARTITIONED BY (b STRING); + +ALTER TABLE table23 ADD CONSTRAINT fk23_1 FOREIGN KEY (a,b) REFERENCES table21(a,b) DISABLE NOVALIDATE RELY; +ALTER TABLE table23 ADD CONSTRAINT pk23_1 PRIMARY KEY (b) DISABLE RELY; + +DESCRIBE FORMATTED table23; diff --git ql/src/test/results/clientpositive/create_with_constraints.q.out ql/src/test/results/clientpositive/create_with_constraints.q.out index 2f3daef..6b7f89a 100644 --- ql/src/test/results/clientpositive/create_with_constraints.q.out +++ ql/src/test/results/clientpositive/create_with_constraints.q.out @@ -100,11 +100,11 @@ POSTHOOK: query: CREATE TABLE table12 (a STRING CONSTRAINT nn12_1 NOT NULL DISAB POSTHOOK: type: CREATETABLE POSTHOOK: Output: database:default POSTHOOK: Output: default@table12 -PREHOOK: query: CREATE TABLE table13 (a STRING NOT NULL DISABLE RELY, b STRING) +PREHOOK: query: CREATE TABLE table13 (b STRING) PARTITIONED BY (a STRING NOT NULL DISABLE RELY) PREHOOK: type: CREATETABLE PREHOOK: Output: database:default PREHOOK: Output: default@table13 -POSTHOOK: query: CREATE TABLE table13 (a STRING NOT NULL DISABLE RELY, b STRING) +POSTHOOK: query: CREATE TABLE table13 (b STRING) PARTITIONED BY (a STRING NOT NULL DISABLE RELY) POSTHOOK: type: CREATETABLE POSTHOOK: Output: database:default POSTHOOK: Output: default@table13 @@ -140,11 +140,11 @@ POSTHOOK: query: CREATE TABLE table17 (a STRING CONSTRAINT uk17_1 UNIQUE DISABLE POSTHOOK: type: CREATETABLE POSTHOOK: Output: database:default POSTHOOK: Output: default@table17 -PREHOOK: query: CREATE TABLE table18 (a STRING, b STRING, CONSTRAINT uk18_1 UNIQUE (b) DISABLE RELY) +PREHOOK: query: CREATE TABLE table18 (a STRING, CONSTRAINT uk18_1 UNIQUE (b) DISABLE RELY) PARTITIONED BY (b STRING) PREHOOK: type: CREATETABLE PREHOOK: Output: database:default PREHOOK: Output: default@table18 -POSTHOOK: query: CREATE TABLE table18 (a STRING, b STRING, CONSTRAINT uk18_1 UNIQUE (b) DISABLE RELY) +POSTHOOK: query: CREATE TABLE table18 (a STRING, CONSTRAINT uk18_1 UNIQUE (b) DISABLE RELY) PARTITIONED BY (b STRING) POSTHOOK: type: CREATETABLE POSTHOOK: Output: database:default POSTHOOK: Output: default@table18 @@ -164,11 +164,11 @@ POSTHOOK: query: CREATE TABLE table20 (a STRING, b STRING, CONSTRAINT uk20_1 UNI POSTHOOK: type: CREATETABLE POSTHOOK: Output: database:default POSTHOOK: Output: default@table20 -PREHOOK: query: CREATE TABLE table21 (a STRING, b STRING, CONSTRAINT uk21_1 UNIQUE (a,b) DISABLE) +PREHOOK: query: CREATE TABLE table21 (a STRING, CONSTRAINT uk21_1 UNIQUE (a,b) DISABLE) PARTITIONED BY (b STRING) PREHOOK: type: CREATETABLE PREHOOK: Output: database:default PREHOOK: Output: default@table21 -POSTHOOK: query: CREATE TABLE table21 (a STRING, b STRING, CONSTRAINT uk21_1 UNIQUE (a,b) DISABLE) +POSTHOOK: query: CREATE TABLE table21 (a STRING, CONSTRAINT uk21_1 UNIQUE (a,b) DISABLE) PARTITIONED BY (b STRING) POSTHOOK: type: CREATETABLE POSTHOOK: Output: database:default POSTHOOK: Output: default@table21 @@ -325,8 +325,12 @@ PREHOOK: Input: default@table13 POSTHOOK: query: DESCRIBE EXTENDED table13 POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@table13 -a string b string +a string + +# Partition Information +# col_name data_type comment +a string #### A masked pattern was here #### Constraints Not Null Constraints for default.table13:[ {Constraint Name: #### A masked pattern was here ####, Column Name: a}] @@ -381,6 +385,10 @@ POSTHOOK: Input: default@table18 a string b string +# Partition Information +# col_name data_type comment +b string + #### A masked pattern was here #### Constraints Unique Constraints for default.table18:[ {Constraint Name: uk18_1, (Column Name: b, Key Sequence: 1)}] PREHOOK: query: DESCRIBE EXTENDED table19 @@ -415,6 +423,10 @@ POSTHOOK: Input: default@table21 a string b string +# Partition Information +# col_name data_type comment +b string + #### A masked pattern was here #### Constraints Unique Constraints for default.table21:[ {Constraint Name: uk21_1, (Column Name: a, Key Sequence: 1), (Column Name: b, Key Sequence: 2)}] PREHOOK: query: DESCRIBE EXTENDED table22 @@ -986,9 +998,12 @@ POSTHOOK: query: DESCRIBE FORMATTED table13 POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@table13 # col_name data_type comment -a string b string +# Partition Information +# col_name data_type comment +a string + # Detailed Table Information Database: default #### A masked pattern was here #### @@ -996,8 +1011,9 @@ 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\"}} + COLUMN_STATS_ACCURATE {\"BASIC_STATS\":\"true\"} numFiles 0 + numPartitions 0 numRows 0 rawDataSize 0 totalSize 0 @@ -1181,6 +1197,9 @@ POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@table18 # col_name data_type comment a string + +# Partition Information +# col_name data_type comment b string # Detailed Table Information @@ -1190,8 +1209,9 @@ 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\"}} + COLUMN_STATS_ACCURATE {\"BASIC_STATS\":\"true\"} numFiles 0 + numPartitions 0 numRows 0 rawDataSize 0 totalSize 0 @@ -1312,6 +1332,9 @@ POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@table21 # col_name data_type comment a string + +# Partition Information +# col_name data_type comment b string # Detailed Table Information @@ -1321,8 +1344,9 @@ 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\"}} + COLUMN_STATS_ACCURATE {\"BASIC_STATS\":\"true\"} numFiles 0 + numPartitions 0 numRows 0 rawDataSize 0 totalSize 0 @@ -1397,6 +1421,10 @@ PREHOOK: query: ALTER TABLE table6 DROP CONSTRAINT fk4 PREHOOK: type: ALTERTABLE_DROPCONSTRAINT POSTHOOK: query: ALTER TABLE table6 DROP CONSTRAINT fk4 POSTHOOK: type: ALTERTABLE_DROPCONSTRAINT +PREHOOK: query: ALTER TABLE table8 DROP CONSTRAINT pk8 +PREHOOK: type: ALTERTABLE_DROPCONSTRAINT +POSTHOOK: query: ALTER TABLE table8 DROP CONSTRAINT pk8 +POSTHOOK: type: ALTERTABLE_DROPCONSTRAINT PREHOOK: query: ALTER TABLE table16 DROP CONSTRAINT nn16_1 PREHOOK: type: ALTERTABLE_DROPCONSTRAINT POSTHOOK: query: ALTER TABLE table16 DROP CONSTRAINT nn16_1 @@ -1449,6 +1477,16 @@ y string #### A masked pattern was here #### Constraints Primary Key for default.table6:[x], Constraint Name: #### A masked pattern was here #### +PREHOOK: query: DESCRIBE EXTENDED table8 +PREHOOK: type: DESCTABLE +PREHOOK: Input: default@table8 +POSTHOOK: query: DESCRIBE EXTENDED table8 +POSTHOOK: type: DESCTABLE +POSTHOOK: Input: default@table8 +a string +b string + +#### A masked pattern was here #### PREHOOK: query: DESCRIBE EXTENDED table16 PREHOOK: type: DESCTABLE PREHOOK: Input: default@table16 @@ -1468,6 +1506,10 @@ POSTHOOK: Input: default@table18 a string b string +# Partition Information +# col_name data_type comment +b string + #### A masked pattern was here #### PREHOOK: query: DESCRIBE FORMATTED table2 PREHOOK: type: DESCTABLE @@ -1638,6 +1680,40 @@ Storage Desc Params: Table: default.table6 Constraint Name: #### A masked pattern was here #### Column Names: x +PREHOOK: query: DESCRIBE FORMATTED table8 +PREHOOK: type: DESCTABLE +PREHOOK: Input: default@table8 +POSTHOOK: query: DESCRIBE FORMATTED table8 +POSTHOOK: type: DESCTABLE +POSTHOOK: Input: default@table8 +# 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 PREHOOK: query: DESCRIBE FORMATTED table16 PREHOOK: type: DESCTABLE PREHOOK: Input: default@table16 @@ -1680,6 +1756,9 @@ POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@table18 # col_name data_type comment a string + +# Partition Information +# col_name data_type comment b string # Detailed Table Information @@ -1689,8 +1768,9 @@ 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\"}} + COLUMN_STATS_ACCURATE {\"BASIC_STATS\":\"true\"} numFiles 0 + numPartitions 0 numRows 0 rawDataSize 0 totalSize 0 @@ -1718,6 +1798,10 @@ PREHOOK: query: ALTER TABLE table6 ADD CONSTRAINT fk4 FOREIGN KEY (y) REFERENCES PREHOOK: type: ALTERTABLE_ADDCONSTRAINT POSTHOOK: query: ALTER TABLE table6 ADD CONSTRAINT fk4 FOREIGN KEY (y) REFERENCES table1(a) DISABLE NOVALIDATE POSTHOOK: type: ALTERTABLE_ADDCONSTRAINT +PREHOOK: query: ALTER TABLE table8 ADD CONSTRAINT pk8_2 PRIMARY KEY (a, b) DISABLE NOVALIDATE RELY +PREHOOK: type: ALTERTABLE_ADDCONSTRAINT +POSTHOOK: query: ALTER TABLE table8 ADD CONSTRAINT pk8_2 PRIMARY KEY (a, b) DISABLE NOVALIDATE RELY +POSTHOOK: type: ALTERTABLE_ADDCONSTRAINT PREHOOK: query: ALTER TABLE table16 CHANGE a a STRING REFERENCES table4(x) DISABLE NOVALIDATE PREHOOK: type: ALTERTABLE_RENAMECOL PREHOOK: Input: default@table16 @@ -1873,6 +1957,47 @@ Parent Column Name:default.table1.a Column Name:y Key Sequence:1 Constraint Name: #### A masked pattern was here #### Parent Column Name:default.table2.a Column Name:x Key Sequence:1 +PREHOOK: query: DESCRIBE FORMATTED table8 +PREHOOK: type: DESCTABLE +PREHOOK: Input: default@table8 +POSTHOOK: query: DESCRIBE FORMATTED table8 +POSTHOOK: type: DESCTABLE +POSTHOOK: Input: default@table8 +# 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.table8 +Constraint Name: pk8_2 +Column Names: a b PREHOOK: query: DESCRIBE FORMATTED table16 PREHOOK: type: DESCTABLE PREHOOK: Input: default@table16 @@ -1916,6 +2041,9 @@ POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@table18 # col_name data_type comment a string + +# Partition Information +# col_name data_type comment b string # Detailed Table Information @@ -1925,8 +2053,9 @@ 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\"}} + COLUMN_STATS_ACCURATE {\"BASIC_STATS\":\"true\"} numFiles 0 + numPartitions 0 numRows 0 rawDataSize 0 totalSize 0 @@ -2020,9 +2149,12 @@ POSTHOOK: query: DESCRIBE FORMATTED table13 POSTHOOK: type: DESCTABLE POSTHOOK: Input: default@table13 # col_name data_type comment -a string b string +# Partition Information +# col_name data_type comment +a string + # Detailed Table Information Database: default #### A masked pattern was here #### @@ -2030,9 +2162,10 @@ 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\"}} + COLUMN_STATS_ACCURATE {\"BASIC_STATS\":\"true\"} #### A masked pattern was here #### numFiles 0 + numPartitions 0 numRows 0 rawDataSize 0 totalSize 0 @@ -2356,3 +2489,64 @@ Table: dbconstraint.table2 Constraint Name: #### A masked pattern was here #### Column Name: b +PREHOOK: query: CREATE TABLE table23 (a STRING) PARTITIONED BY (b STRING) +PREHOOK: type: CREATETABLE +PREHOOK: Output: database:default +PREHOOK: Output: default@table23 +POSTHOOK: query: CREATE TABLE table23 (a STRING) PARTITIONED BY (b STRING) +POSTHOOK: type: CREATETABLE +POSTHOOK: Output: database:default +POSTHOOK: Output: default@table23 +PREHOOK: query: ALTER TABLE table23 ADD CONSTRAINT fk23_1 FOREIGN KEY (a,b) REFERENCES table21(a,b) DISABLE NOVALIDATE RELY +PREHOOK: type: ALTERTABLE_ADDCONSTRAINT +POSTHOOK: query: ALTER TABLE table23 ADD CONSTRAINT fk23_1 FOREIGN KEY (a,b) REFERENCES table21(a,b) DISABLE NOVALIDATE RELY +POSTHOOK: type: ALTERTABLE_ADDCONSTRAINT +PREHOOK: query: ALTER TABLE table23 ADD CONSTRAINT pk23_1 PRIMARY KEY (b) DISABLE RELY +PREHOOK: type: ALTERTABLE_ADDCONSTRAINT +POSTHOOK: query: ALTER TABLE table23 ADD CONSTRAINT pk23_1 PRIMARY KEY (b) DISABLE RELY +POSTHOOK: type: ALTERTABLE_ADDCONSTRAINT +PREHOOK: query: DESCRIBE FORMATTED table23 +PREHOOK: type: DESCTABLE +PREHOOK: Input: default@table23 +POSTHOOK: query: DESCRIBE FORMATTED table23 +POSTHOOK: type: DESCTABLE +POSTHOOK: Input: default@table23 +# col_name data_type comment +a string + +# Partition Information +# col_name data_type comment +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\"} + numFiles 0 + numPartitions 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.table23 +Constraint Name: pk23_1 +Column Names: b diff --git standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java index fc7235b..d9155c4 100644 --- standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java +++ standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java @@ -134,7 +134,7 @@ @TableName private String DBS, TBLS, PARTITIONS, DATABASE_PARAMS, PARTITION_PARAMS, SORT_COLS, SD_PARAMS, SDS, SERDES, SKEWED_STRING_LIST_VALUES, SKEWED_VALUES, BUCKETING_COLS, SKEWED_COL_NAMES, - SKEWED_COL_VALUE_LOC_MAP, COLUMNS_V2, SERDE_PARAMS, PART_COL_STATS, KEY_CONSTRAINTS, + SKEWED_COL_VALUE_LOC_MAP, COLUMNS_V2, PARTITION_KEYS, SERDE_PARAMS, PART_COL_STATS, KEY_CONSTRAINTS, TAB_COL_STATS, PARTITION_KEY_VALS; public MetaStoreDirectSql(PersistenceManager pm, Configuration conf, String schema) { @@ -2006,26 +2006,32 @@ public void closeAllQueries() { public List getForeignKeys(String parent_db_name, String parent_tbl_name, String foreign_db_name, String foreign_tbl_name) throws MetaException { List ret = new ArrayList(); String queryText = - "SELECT \"D2\".\"NAME\", \"T2\".\"TBL_NAME\", \"C2\".\"COLUMN_NAME\"," - + "" + DBS + ".\"NAME\", " + TBLS + ".\"TBL_NAME\", " + COLUMNS_V2 + ".\"COLUMN_NAME\", " + "SELECT \"D2\".\"NAME\", \"T2\".\"TBL_NAME\", " + + "CASE WHEN \"C2\".\"COLUMN_NAME\" IS NOT NULL THEN \"C2\".\"COLUMN_NAME\" " + + "ELSE \"P2\".\"PKEY_NAME\" END, " + + "" + DBS + ".\"NAME\", " + TBLS + ".\"TBL_NAME\", " + + "CASE WHEN " + COLUMNS_V2 + ".\"COLUMN_NAME\" IS NOT NULL THEN " + COLUMNS_V2 + ".\"COLUMN_NAME\" " + + "ELSE " + PARTITION_KEYS + ".\"PKEY_NAME\" END, " + "" + KEY_CONSTRAINTS + ".\"POSITION\", " + KEY_CONSTRAINTS + ".\"UPDATE_RULE\", " + KEY_CONSTRAINTS + ".\"DELETE_RULE\", " + "" + KEY_CONSTRAINTS + ".\"CONSTRAINT_NAME\" , \"KEY_CONSTRAINTS2\".\"CONSTRAINT_NAME\", " + KEY_CONSTRAINTS + ".\"ENABLE_VALIDATE_RELY\" " + " from " + TBLS + " " - + " INNER join " + KEY_CONSTRAINTS + " ON " + TBLS + ".\"TBL_ID\" = " + KEY_CONSTRAINTS + ".\"CHILD_TBL_ID\" " - + " INNER join " + KEY_CONSTRAINTS + " \"KEY_CONSTRAINTS2\" ON \"KEY_CONSTRAINTS2\".\"PARENT_TBL_ID\" = " + KEY_CONSTRAINTS + ".\"PARENT_TBL_ID\" " + + " INNER JOIN " + KEY_CONSTRAINTS + " ON " + TBLS + ".\"TBL_ID\" = " + KEY_CONSTRAINTS + ".\"CHILD_TBL_ID\" " + + " INNER JOIN " + KEY_CONSTRAINTS + " \"KEY_CONSTRAINTS2\" ON \"KEY_CONSTRAINTS2\".\"PARENT_TBL_ID\" = " + KEY_CONSTRAINTS + ".\"PARENT_TBL_ID\" " + " AND \"KEY_CONSTRAINTS2\".\"PARENT_CD_ID\" = " + KEY_CONSTRAINTS + ".\"PARENT_CD_ID\" AND " + " \"KEY_CONSTRAINTS2\".\"PARENT_INTEGER_IDX\" = " + KEY_CONSTRAINTS + ".\"PARENT_INTEGER_IDX\" " - + " INNER join " + DBS + " ON " + TBLS + ".\"DB_ID\" = " + DBS + ".\"DB_ID\" " - + " INNER join " + TBLS + " \"T2\" ON " + KEY_CONSTRAINTS + ".\"PARENT_TBL_ID\" = \"T2\".\"TBL_ID\" " - + " INNER join " + DBS + " \"D2\" ON \"T2\".\"DB_ID\" = \"D2\".\"DB_ID\" " - + " INNER JOIN " + COLUMNS_V2 + " ON " + COLUMNS_V2 + ".\"CD_ID\" = " + KEY_CONSTRAINTS + ".\"CHILD_CD_ID\" AND " + + " INNER JOIN " + DBS + " ON " + TBLS + ".\"DB_ID\" = " + DBS + ".\"DB_ID\" " + + " INNER JOIN " + TBLS + " \"T2\" ON " + KEY_CONSTRAINTS + ".\"PARENT_TBL_ID\" = \"T2\".\"TBL_ID\" " + + " INNER JOIN " + DBS + " \"D2\" ON \"T2\".\"DB_ID\" = \"D2\".\"DB_ID\" " + + " LEFT OUTER JOIN " + COLUMNS_V2 + " ON " + COLUMNS_V2 + ".\"CD_ID\" = " + KEY_CONSTRAINTS + ".\"CHILD_CD_ID\" AND " + " " + COLUMNS_V2 + ".\"INTEGER_IDX\" = " + KEY_CONSTRAINTS + ".\"CHILD_INTEGER_IDX\" " - + " INNER JOIN " + COLUMNS_V2 + " \"C2\" ON \"C2\".\"CD_ID\" = " + KEY_CONSTRAINTS + ".\"PARENT_CD_ID\" AND " + + " LEFT OUTER JOIN " + PARTITION_KEYS + " ON " + TBLS + ".\"TBL_ID\" = " + PARTITION_KEYS + ".\"TBL_ID\" AND " + + " " + PARTITION_KEYS + ".\"INTEGER_IDX\" = " + KEY_CONSTRAINTS + ".\"CHILD_INTEGER_IDX\" " + + " LEFT OUTER JOIN " + COLUMNS_V2 + " \"C2\" ON \"C2\".\"CD_ID\" = " + KEY_CONSTRAINTS + ".\"PARENT_CD_ID\" AND " + " \"C2\".\"INTEGER_IDX\" = " + KEY_CONSTRAINTS + ".\"PARENT_INTEGER_IDX\" " - + " WHERE " + KEY_CONSTRAINTS + ".\"CONSTRAINT_TYPE\" = " - + MConstraint.FOREIGN_KEY_CONSTRAINT - + " AND \"KEY_CONSTRAINTS2\".\"CONSTRAINT_TYPE\" = " - + MConstraint.PRIMARY_KEY_CONSTRAINT + " AND" + + " LEFT OUTER JOIN " + PARTITION_KEYS + " \"P2\" ON \"P2\".\"TBL_ID\" = " + TBLS + ".\"TBL_ID\" AND " + + " \"P2\".\"INTEGER_IDX\" = " + KEY_CONSTRAINTS + ".\"PARENT_INTEGER_IDX\" " + + " WHERE " + KEY_CONSTRAINTS + ".\"CONSTRAINT_TYPE\" = " + MConstraint.FOREIGN_KEY_CONSTRAINT + + " AND \"KEY_CONSTRAINTS2\".\"CONSTRAINT_TYPE\" = " + MConstraint.PRIMARY_KEY_CONSTRAINT + " AND" + (foreign_db_name == null ? "" : " " + DBS + ".\"NAME\" = ? AND") + (foreign_tbl_name == null ? "" : " " + TBLS + ".\"TBL_NAME\" = ? AND") + (parent_tbl_name == null ? "" : " \"T2\".\"TBL_NAME\" = ? AND") @@ -2084,14 +2090,17 @@ public void closeAllQueries() { public List getPrimaryKeys(String db_name, String tbl_name) throws MetaException { List ret = new ArrayList(); String queryText = - "SELECT " + DBS + ".\"NAME\", " + TBLS + ".\"TBL_NAME\", " + COLUMNS_V2 + ".\"COLUMN_NAME\"," - + "" + KEY_CONSTRAINTS + ".\"POSITION\", " + "SELECT " + DBS + ".\"NAME\", " + TBLS + ".\"TBL_NAME\", " + + "CASE WHEN " + COLUMNS_V2 + ".\"COLUMN_NAME\" IS NOT NULL THEN " + COLUMNS_V2 + ".\"COLUMN_NAME\" " + + "ELSE " + PARTITION_KEYS + ".\"PKEY_NAME\" END, " + KEY_CONSTRAINTS + ".\"POSITION\", " + "" + KEY_CONSTRAINTS + ".\"CONSTRAINT_NAME\", " + KEY_CONSTRAINTS + ".\"ENABLE_VALIDATE_RELY\" " + " from " + TBLS + " " - + " INNER join " + KEY_CONSTRAINTS + " ON " + TBLS + ".\"TBL_ID\" = " + KEY_CONSTRAINTS + ".\"PARENT_TBL_ID\" " - + " INNER join " + DBS + " ON " + TBLS + ".\"DB_ID\" = " + DBS + ".\"DB_ID\" " - + " INNER JOIN " + COLUMNS_V2 + " ON " + COLUMNS_V2 + ".\"CD_ID\" = " + KEY_CONSTRAINTS + ".\"PARENT_CD_ID\" AND " + + " INNER JOIN " + KEY_CONSTRAINTS + " ON " + TBLS + ".\"TBL_ID\" = " + KEY_CONSTRAINTS + ".\"PARENT_TBL_ID\" " + + " INNER JOIN " + DBS + " ON " + TBLS + ".\"DB_ID\" = " + DBS + ".\"DB_ID\" " + + " LEFT OUTER JOIN " + COLUMNS_V2 + " ON " + COLUMNS_V2 + ".\"CD_ID\" = " + KEY_CONSTRAINTS + ".\"PARENT_CD_ID\" AND " + " " + COLUMNS_V2 + ".\"INTEGER_IDX\" = " + KEY_CONSTRAINTS + ".\"PARENT_INTEGER_IDX\" " + + " LEFT OUTER JOIN " + PARTITION_KEYS + " ON " + TBLS + ".\"TBL_ID\" = " + PARTITION_KEYS + ".\"TBL_ID\" AND " + + " " + PARTITION_KEYS + ".\"INTEGER_IDX\" = " + KEY_CONSTRAINTS + ".\"PARENT_INTEGER_IDX\" " + " WHERE " + KEY_CONSTRAINTS + ".\"CONSTRAINT_TYPE\" = "+ MConstraint.PRIMARY_KEY_CONSTRAINT + " AND" + (db_name == null ? "" : " " + DBS + ".\"NAME\" = ? AND") + (tbl_name == null ? "" : " " + TBLS + ".\"TBL_NAME\" = ? ") ; @@ -2136,14 +2145,17 @@ public void closeAllQueries() { throws MetaException { List ret = new ArrayList(); String queryText = - "SELECT " + DBS + ".\"NAME\", " + TBLS + ".\"TBL_NAME\", " + COLUMNS_V2 + ".\"COLUMN_NAME\"," - + "" + KEY_CONSTRAINTS + ".\"POSITION\", " - + "" + KEY_CONSTRAINTS + ".\"CONSTRAINT_NAME\", " + KEY_CONSTRAINTS + ".\"ENABLE_VALIDATE_RELY\" " + "SELECT " + DBS + ".\"NAME\", " + TBLS + ".\"TBL_NAME\", " + + "CASE WHEN " + COLUMNS_V2 + ".\"COLUMN_NAME\" IS NOT NULL THEN " + COLUMNS_V2 + ".\"COLUMN_NAME\" " + + "ELSE " + PARTITION_KEYS + ".\"PKEY_NAME\" END, " + KEY_CONSTRAINTS + ".\"POSITION\", " + + KEY_CONSTRAINTS + ".\"CONSTRAINT_NAME\", " + KEY_CONSTRAINTS + ".\"ENABLE_VALIDATE_RELY\" " + " from " + TBLS + " " - + " INNER join " + KEY_CONSTRAINTS + " ON " + TBLS + ".\"TBL_ID\" = " + KEY_CONSTRAINTS + ".\"PARENT_TBL_ID\" " - + " INNER join " + DBS + " ON " + TBLS + ".\"DB_ID\" = " + DBS + ".\"DB_ID\" " - + " INNER JOIN " + COLUMNS_V2 + " ON " + COLUMNS_V2 + ".\"CD_ID\" = " + KEY_CONSTRAINTS + ".\"PARENT_CD_ID\" AND " + + " INNER JOIN " + KEY_CONSTRAINTS + " ON " + TBLS + ".\"TBL_ID\" = " + KEY_CONSTRAINTS + ".\"PARENT_TBL_ID\" " + + " INNER JOIN " + DBS + " ON " + TBLS + ".\"DB_ID\" = " + DBS + ".\"DB_ID\" " + + " LEFT OUTER JOIN " + COLUMNS_V2 + " ON " + COLUMNS_V2 + ".\"CD_ID\" = " + KEY_CONSTRAINTS + ".\"PARENT_CD_ID\" AND " + " " + COLUMNS_V2 + ".\"INTEGER_IDX\" = " + KEY_CONSTRAINTS + ".\"PARENT_INTEGER_IDX\" " + + " LEFT OUTER JOIN " + PARTITION_KEYS + " ON " + TBLS + ".\"TBL_ID\" = " + PARTITION_KEYS + ".\"TBL_ID\" AND " + + " " + PARTITION_KEYS + ".\"INTEGER_IDX\" = " + KEY_CONSTRAINTS + ".\"PARENT_INTEGER_IDX\" " + " WHERE " + KEY_CONSTRAINTS + ".\"CONSTRAINT_TYPE\" = "+ MConstraint.UNIQUE_CONSTRAINT + " AND" + (db_name == null ? "" : " " + DBS + ".\"NAME\" = ? AND") + (tbl_name == null ? "" : " " + TBLS + ".\"TBL_NAME\" = ? ") ; @@ -2188,13 +2200,17 @@ public void closeAllQueries() { throws MetaException { List ret = new ArrayList(); String queryText = - "SELECT " + DBS + ".\"NAME\", " + TBLS + ".\"TBL_NAME\", " + COLUMNS_V2 + ".\"COLUMN_NAME\"," + "SELECT " + DBS + ".\"NAME\", " + TBLS + ".\"TBL_NAME\"," + + "CASE WHEN " + COLUMNS_V2 + ".\"COLUMN_NAME\" IS NOT NULL THEN " + COLUMNS_V2 + ".\"COLUMN_NAME\" " + + "ELSE " + PARTITION_KEYS + ".\"PKEY_NAME\" END, " + "" + KEY_CONSTRAINTS + ".\"CONSTRAINT_NAME\", " + KEY_CONSTRAINTS + ".\"ENABLE_VALIDATE_RELY\" " + " from " + TBLS + " " - + " INNER join " + KEY_CONSTRAINTS + " ON " + TBLS + ".\"TBL_ID\" = " + KEY_CONSTRAINTS + ".\"PARENT_TBL_ID\" " - + " INNER join " + DBS + " ON " + TBLS + ".\"DB_ID\" = " + DBS + ".\"DB_ID\" " - + " INNER JOIN " + COLUMNS_V2 + " ON " + COLUMNS_V2 + ".\"CD_ID\" = " + KEY_CONSTRAINTS + ".\"PARENT_CD_ID\" AND " + + " INNER JOIN " + KEY_CONSTRAINTS + " ON " + TBLS + ".\"TBL_ID\" = " + KEY_CONSTRAINTS + ".\"PARENT_TBL_ID\" " + + " INNER JOIN " + DBS + " ON " + TBLS + ".\"DB_ID\" = " + DBS + ".\"DB_ID\" " + + " LEFT OUTER JOIN " + COLUMNS_V2 + " ON " + COLUMNS_V2 + ".\"CD_ID\" = " + KEY_CONSTRAINTS + ".\"PARENT_CD_ID\" AND " + " " + COLUMNS_V2 + ".\"INTEGER_IDX\" = " + KEY_CONSTRAINTS + ".\"PARENT_INTEGER_IDX\" " + + " LEFT OUTER JOIN " + PARTITION_KEYS + " ON " + TBLS + ".\"TBL_ID\" = " + PARTITION_KEYS + ".\"TBL_ID\" AND " + + " " + PARTITION_KEYS + ".\"INTEGER_IDX\" = " + KEY_CONSTRAINTS + ".\"PARENT_INTEGER_IDX\" " + " WHERE " + KEY_CONSTRAINTS + ".\"CONSTRAINT_TYPE\" = "+ MConstraint.NOT_NULL_CONSTRAINT + " AND" + (db_name == null ? "" : " " + DBS + ".\"NAME\" = ? AND") + (tbl_name == null ? "" : " " + TBLS + ".\"TBL_NAME\" = ? ") ; diff --git standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java index 63081e7..eff62aa 100644 --- standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java +++ standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java @@ -78,8 +78,6 @@ import javax.jdo.identity.IntIdentity; import javax.sql.DataSource; -import com.codahale.metrics.Counter; -import com.codahale.metrics.MetricRegistry; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.hadoop.classification.InterfaceAudience; @@ -124,9 +122,6 @@ import org.apache.hadoop.hive.metastore.api.PrincipalType; import org.apache.hadoop.hive.metastore.api.PrivilegeBag; import org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo; -import org.apache.hadoop.hive.metastore.api.WMResourcePlan; -import org.apache.hadoop.hive.metastore.api.WMResourcePlanStatus; -import org.apache.hadoop.hive.metastore.api.WMTrigger; import org.apache.hadoop.hive.metastore.api.ResourceType; import org.apache.hadoop.hive.metastore.api.ResourceUri; import org.apache.hadoop.hive.metastore.api.Role; @@ -144,10 +139,13 @@ import org.apache.hadoop.hive.metastore.api.UnknownDBException; import org.apache.hadoop.hive.metastore.api.UnknownPartitionException; import org.apache.hadoop.hive.metastore.api.UnknownTableException; +import org.apache.hadoop.hive.metastore.api.WMResourcePlan; +import org.apache.hadoop.hive.metastore.api.WMResourcePlanStatus; +import org.apache.hadoop.hive.metastore.api.WMTrigger; import org.apache.hadoop.hive.metastore.conf.MetastoreConf; +import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars; import org.apache.hadoop.hive.metastore.datasource.DataSourceProvider; import org.apache.hadoop.hive.metastore.datasource.DataSourceProviderFactory; -import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars; import org.apache.hadoop.hive.metastore.metrics.Metrics; import org.apache.hadoop.hive.metastore.metrics.MetricsConstants; import org.apache.hadoop.hive.metastore.model.MColumnDescriptor; @@ -160,6 +158,7 @@ import org.apache.hadoop.hive.metastore.model.MGlobalPrivilege; import org.apache.hadoop.hive.metastore.model.MIndex; import org.apache.hadoop.hive.metastore.model.MMasterKey; +import org.apache.hadoop.hive.metastore.model.MMetastoreDBProperties; import org.apache.hadoop.hive.metastore.model.MNotificationLog; import org.apache.hadoop.hive.metastore.model.MNotificationNextId; import org.apache.hadoop.hive.metastore.model.MOrder; @@ -168,9 +167,6 @@ import org.apache.hadoop.hive.metastore.model.MPartitionColumnStatistics; import org.apache.hadoop.hive.metastore.model.MPartitionEvent; import org.apache.hadoop.hive.metastore.model.MPartitionPrivilege; -import org.apache.hadoop.hive.metastore.model.MWMResourcePlan; -import org.apache.hadoop.hive.metastore.model.MWMTrigger; -import org.apache.hadoop.hive.metastore.model.MWMResourcePlan.Status; import org.apache.hadoop.hive.metastore.model.MResourceUri; import org.apache.hadoop.hive.metastore.model.MRole; import org.apache.hadoop.hive.metastore.model.MRoleMap; @@ -183,7 +179,9 @@ import org.apache.hadoop.hive.metastore.model.MTablePrivilege; import org.apache.hadoop.hive.metastore.model.MType; import org.apache.hadoop.hive.metastore.model.MVersionTable; -import org.apache.hadoop.hive.metastore.model.MMetastoreDBProperties; +import org.apache.hadoop.hive.metastore.model.MWMResourcePlan; +import org.apache.hadoop.hive.metastore.model.MWMResourcePlan.Status; +import org.apache.hadoop.hive.metastore.model.MWMTrigger; import org.apache.hadoop.hive.metastore.parser.ExpressionTree; import org.apache.hadoop.hive.metastore.parser.ExpressionTree.FilterBuilder; import org.apache.hadoop.hive.metastore.partition.spec.PartitionSpecProxy; @@ -206,6 +204,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.codahale.metrics.Counter; +import com.codahale.metrics.MetricRegistry; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -3959,8 +3959,12 @@ private String getGuidFromDB() throws MetaException { if (childTable == null) { throw new InvalidObjectException("Child table not found: " + fkTableName); } - final MColumnDescriptor childCD = retrieveCD ? nChildTable.mcd : childTable.getSd().getCD(); - final List childCols = childCD.getCols(); + MColumnDescriptor childCD = retrieveCD ? nChildTable.mcd : childTable.getSd().getCD(); + final List childCols = childCD == null || childCD.getCols() == null ? + new ArrayList<>() : new ArrayList<>(childCD.getCols()); + if (childTable.getPartitionKeys() != null) { + childCols.addAll(childTable.getPartitionKeys()); + } final String pkTableDB = normalizeIdentifier(foreignKeys.get(i).getPktable_db()); final String pkTableName = normalizeIdentifier(foreignKeys.get(i).getPktable_name()); @@ -3969,7 +3973,7 @@ private String getGuidFromDB() throws MetaException { // referencing another table instead of self for the primary key. final AttachedMTableInfo nParentTable; final MTable parentTable; - final MColumnDescriptor parentCD; + MColumnDescriptor parentCD; final List parentCols; final List existingTablePrimaryKeys; final List existingTableUniqueConstraints; @@ -3988,7 +3992,11 @@ private String getGuidFromDB() throws MetaException { throw new InvalidObjectException("Parent table not found: " + pkTableName); } parentCD = nParentTable.mcd; - parentCols = parentCD == null ? null : parentCD.getCols(); + parentCols = parentCD == null || parentCD.getCols() == null ? + new ArrayList<>() : new ArrayList<>(parentCD.getCols()); + if (parentTable.getPartitionKeys() != null) { + parentCols.addAll(parentTable.getPartitionKeys()); + } existingTablePrimaryKeys = getPrimaryKeys(pkTableDB, pkTableName); existingTableUniqueConstraints = getUniqueConstraints(pkTableDB, pkTableName); } @@ -4008,15 +4016,27 @@ private String getGuidFromDB() throws MetaException { for (; i < foreignKeys.size(); i++) { final SQLForeignKey foreignKey = foreignKeys.get(i); final String fkColumnName = normalizeIdentifier(foreignKey.getFkcolumn_name()); - int childIntegerIndex = getColumnIndexFromTableColumns(childCols, fkColumnName); + int childIntegerIndex = getColumnIndexFromTableColumns(childCD.getCols(), fkColumnName); if (childIntegerIndex == -1) { - throw new InvalidObjectException("Child column not found: " + fkColumnName); + if (childTable.getPartitionKeys() != null) { + childCD = null; + childIntegerIndex = getColumnIndexFromTableColumns(childTable.getPartitionKeys(), fkColumnName); + } + if (childIntegerIndex == -1) { + throw new InvalidObjectException("Child column not found: " + fkColumnName); + } } final String pkColumnName = normalizeIdentifier(foreignKey.getPkcolumn_name()); - int parentIntegerIndex = getColumnIndexFromTableColumns(parentCols, pkColumnName); + int parentIntegerIndex = getColumnIndexFromTableColumns(parentCD.getCols(), pkColumnName); if (parentIntegerIndex == -1) { - throw new InvalidObjectException("Parent column not found: " + pkColumnName); + if (parentTable.getPartitionKeys() != null) { + parentCD = null; + parentIntegerIndex = getColumnIndexFromTableColumns(parentTable.getPartitionKeys(), pkColumnName); + } + if (parentIntegerIndex == -1) { + throw new InvalidObjectException("Parent column not found: " + pkColumnName); + } } if (foreignKey.getFk_name() == null) { @@ -4163,11 +4183,15 @@ private static String generateColNameTypeSignature(String colName, String colTyp } MColumnDescriptor parentCD = retrieveCD ? nParentTable.mcd : parentTable.getSd().getCD(); - int parentIntegerIndex = - getColumnIndexFromTableColumns(parentCD == null ? null : parentCD.getCols(), columnName); - + int parentIntegerIndex = getColumnIndexFromTableColumns(parentCD == null ? null : parentCD.getCols(), columnName); if (parentIntegerIndex == -1) { - throw new InvalidObjectException("Parent column not found: " + columnName); + if (parentTable.getPartitionKeys() != null) { + parentCD = null; + parentIntegerIndex = getColumnIndexFromTableColumns(parentTable.getPartitionKeys(), columnName); + } + if (parentIntegerIndex == -1) { + throw new InvalidObjectException("Parent column not found: " + columnName); + } } if (getPrimaryKeyConstraintName( parentTable.getDatabase().getName(), parentTable.getTableName()) != null) { @@ -4229,10 +4253,15 @@ private static String generateColNameTypeSignature(String colName, String colTyp } MColumnDescriptor parentCD = retrieveCD ? nParentTable.mcd : parentTable.getSd().getCD(); - int parentIntegerIndex = - getColumnIndexFromTableColumns(parentCD == null ? null : parentCD.getCols(), columnName); + int parentIntegerIndex = getColumnIndexFromTableColumns(parentCD == null ? null : parentCD.getCols(), columnName); if (parentIntegerIndex == -1) { - throw new InvalidObjectException("Parent column not found: " + columnName); + if (parentTable.getPartitionKeys() != null) { + parentCD = null; + parentIntegerIndex = getColumnIndexFromTableColumns(parentTable.getPartitionKeys(), columnName); + } + if (parentIntegerIndex == -1) { + throw new InvalidObjectException("Parent column not found: " + columnName); + } } if (uks.get(i).getUk_name() == null) { if (uks.get(i).getKey_seq() == 1) { @@ -4290,10 +4319,15 @@ private static String generateColNameTypeSignature(String colName, String colTyp } MColumnDescriptor parentCD = retrieveCD ? nParentTable.mcd : parentTable.getSd().getCD(); - int parentIntegerIndex = - getColumnIndexFromTableColumns(parentCD == null ? null : parentCD.getCols(), columnName); + int parentIntegerIndex = getColumnIndexFromTableColumns(parentCD == null ? null : parentCD.getCols(), columnName); if (parentIntegerIndex == -1) { - throw new InvalidObjectException("Parent column not found: " + columnName); + if (parentTable.getPartitionKeys() != null) { + parentCD = null; + parentIntegerIndex = getColumnIndexFromTableColumns(parentTable.getPartitionKeys(), columnName); + } + if (parentIntegerIndex == -1) { + throw new InvalidObjectException("Parent column not found: " + columnName); + } } if (nns.get(i).getNn_name() == null) { constraintName = generateConstraintName(tableDB, tableName, columnName, "nn"); @@ -9058,13 +9092,15 @@ private static long clearFieldMap(ClassLoaderResolverImpl clri, String mapFieldN primaryKeys = new ArrayList<>(); for (Iterator i = constraints.iterator(); i.hasNext();) { MConstraint currPK = (MConstraint) i.next(); + List cols = currPK.getParentColumn() != null ? + currPK.getParentColumn().getCols() : currPK.getParentTable().getPartitionKeys(); int enableValidateRely = currPK.getEnableValidateRely(); boolean enable = (enableValidateRely & 4) != 0; boolean validate = (enableValidateRely & 2) != 0; boolean rely = (enableValidateRely & 1) != 0; primaryKeys.add(new SQLPrimaryKey(db_name, tbl_name, - currPK.getParentColumn().getCols().get(currPK.getParentIntegerIndex()).getName(), + cols.get(currPK.getParentIntegerIndex()).getName(), currPK.getPosition(), currPK.getConstraintName(), enable, validate, rely)); } @@ -9199,6 +9235,10 @@ private String getPrimaryKeyConstraintName(String db_name, String tbl_name) thro foreignKeys = new ArrayList<>(); for (Iterator i = constraints.iterator(); i.hasNext();) { MConstraint currPKFK = (MConstraint) i.next(); + List parentCols = currPKFK.getParentColumn() != null ? + currPKFK.getParentColumn().getCols() : currPKFK.getParentTable().getPartitionKeys(); + List childCols = currPKFK.getChildColumn() != null ? + currPKFK.getChildColumn().getCols() : currPKFK.getChildTable().getPartitionKeys(); int enableValidateRely = currPKFK.getEnableValidateRely(); boolean enable = (enableValidateRely & 4) != 0; boolean validate = (enableValidateRely & 2) != 0; @@ -9217,10 +9257,10 @@ private String getPrimaryKeyConstraintName(String db_name, String tbl_name) thro foreignKeys.add(new SQLForeignKey( currPKFK.getParentTable().getDatabase().getName(), currPKFK.getParentTable().getDatabase().getName(), - currPKFK.getParentColumn().getCols().get(currPKFK.getParentIntegerIndex()).getName(), + parentCols.get(currPKFK.getParentIntegerIndex()).getName(), currPKFK.getChildTable().getDatabase().getName(), currPKFK.getChildTable().getTableName(), - currPKFK.getChildColumn().getCols().get(currPKFK.getChildIntegerIndex()).getName(), + childCols.get(currPKFK.getChildIntegerIndex()).getName(), currPKFK.getPosition(), currPKFK.getUpdateRule(), currPKFK.getDeleteRule(), @@ -9279,16 +9319,18 @@ private String getPrimaryKeyConstraintName(String db_name, String tbl_name) thro pm.retrieveAll(constraints); uniqueConstraints = new ArrayList<>(); for (Iterator i = constraints.iterator(); i.hasNext();) { - MConstraint currPK = (MConstraint) i.next(); - int enableValidateRely = currPK.getEnableValidateRely(); + MConstraint currConstraint = (MConstraint) i.next(); + List cols = currConstraint.getParentColumn() != null ? + currConstraint.getParentColumn().getCols() : currConstraint.getParentTable().getPartitionKeys(); + int enableValidateRely = currConstraint.getEnableValidateRely(); boolean enable = (enableValidateRely & 4) != 0; boolean validate = (enableValidateRely & 2) != 0; boolean rely = (enableValidateRely & 1) != 0; uniqueConstraints.add(new SQLUniqueConstraint(db_name, tbl_name, - currPK.getParentColumn().getCols().get(currPK.getParentIntegerIndex()).getName(), - currPK.getPosition(), - currPK.getConstraintName(), enable, validate, rely)); + cols.get(currConstraint.getParentIntegerIndex()).getName(), + currConstraint.getPosition(), + currConstraint.getConstraintName(), enable, validate, rely)); } commited = commitTransaction(); } finally { @@ -9348,15 +9390,17 @@ private String getPrimaryKeyConstraintName(String db_name, String tbl_name) thro pm.retrieveAll(constraints); notNullConstraints = new ArrayList<>(); for (Iterator i = constraints.iterator(); i.hasNext();) { - MConstraint currPK = (MConstraint) i.next(); - int enableValidateRely = currPK.getEnableValidateRely(); + MConstraint currConstraint = (MConstraint) i.next(); + List cols = currConstraint.getParentColumn() != null ? + currConstraint.getParentColumn().getCols() : currConstraint.getParentTable().getPartitionKeys(); + int enableValidateRely = currConstraint.getEnableValidateRely(); boolean enable = (enableValidateRely & 4) != 0; boolean validate = (enableValidateRely & 2) != 0; boolean rely = (enableValidateRely & 1) != 0; notNullConstraints.add(new SQLNotNullConstraint(db_name, tbl_name, - currPK.getParentColumn().getCols().get(currPK.getParentIntegerIndex()).getName(), - currPK.getConstraintName(), enable, validate, rely)); + cols.get(currConstraint.getParentIntegerIndex()).getName(), + currConstraint.getConstraintName(), enable, validate, rely)); } commited = commitTransaction(); } finally {