IMPALA-9188: Composite primary keys should use same constraint name
After IMPALA-9104, dataload started failing when USE_CDP_HIVE=true
because of HIVE-16603 (Enforce foreign keys to refer to primary keys or
unique keys), which is in Hive 3 but not Hive 2.
This patch fixes a bug from IMPALA-2112 where Impala was generating a
unique constraint name for each column in a composite primary key,
rather than using the same constraint name for each column.
Testing:
* Ran dataload + core tests with USE_CDP_HIVE=[true/false]
Change-Id: I7a91658945b0355753c3cf05be195757b37edaf4
Reviewed-on: http://gerrit.cloudera.org:8080/14792
Reviewed-by: Sahil Takiar <stakiar@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
diff --git a/fe/src/main/java/org/apache/impala/analysis/TableDef.java b/fe/src/main/java/org/apache/impala/analysis/TableDef.java
index 14dfe05..e196af1 100644
--- a/fe/src/main/java/org/apache/impala/analysis/TableDef.java
+++ b/fe/src/main/java/org/apache/impala/analysis/TableDef.java
@@ -470,6 +470,7 @@
}
Map<String, ColumnDef> colDefsByColName = ColumnDef.mapByColumnNames(columnDefs_);
int keySeq = 1;
+ String constraintName = null;
for (String colName: primaryKeyColNames_) {
colName = colName.toLowerCase();
ColumnDef colDef = colDefsByColName.remove(colName);
@@ -494,7 +495,11 @@
if (primaryKey_.isValidateCstr()) {
throw new AnalysisException("VALIDATE feature is not supported yet.");
}
- String constraintName = generateConstraintName();
+ // All primary keys in a composite key should have the same constraint name. This
+ // is necessary because of HIVE-16603. See IMPALA-9188 for details.
+ if (constraintName == null) {
+ constraintName = generateConstraintName();
+ }
// Each column of a primary key definition will be an SQLPrimaryKey.
sqlPrimaryKeys_.add(new SQLPrimaryKey(getTblName().getDb(), getTbl(),
colDef.getColName(), keySeq++, constraintName, primaryKey_.enableCstr,