You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by st...@apache.org on 2019/11/26 00:04:18 UTC

[impala] 02/02: IMPALA-9188: Composite primary keys should use same constraint name

This is an automated email from the ASF dual-hosted git repository.

stakiar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit 1f792bea4779229acbaaa40d4904df4546658bfb
Author: Sahil Takiar <ta...@gmail.com>
AuthorDate: Sun Nov 24 11:46:16 2019 -0800

    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 <st...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 fe/src/main/java/org/apache/impala/analysis/TableDef.java | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

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 @@ class TableDef {
     }
     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 @@ class TableDef {
         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,