You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ar...@apache.org on 2021/10/20 04:43:59 UTC

[impala] 03/04: IMPALA-10958: Decouple getConstraintsInformation from hive.ql.metadata.Table

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

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

commit cae36149aace90c256131fc4ba30f1cc5dae561e
Author: Yu-Wen Lai <yu...@cloudera.com>
AuthorDate: Tue Sep 28 12:37:18 2021 -0700

    IMPALA-10958: Decouple getConstraintsInformation from
    hive.ql.metadata.Table
    
    After HIVE-22782, ql.metadata.Table object has no methods to set
    PrimaryKeyInfo and ForeignKeyInfo alone. However, we call these two
    functions In DescribeResultFactory to set constraints and pass the
    table into HiveMetadataFormatUtils. Instead of calling the methods
    from table, we can directly pass PrimaryKeyInfo and ForeignKeyInfo
    to HiveMetadataFormatUtils so that Impala won't be influenced even
    though the table class changes interface.
    
    Additionally, we can get rid of ql.metadata.Table for
    getTableInformation altogether since it just needs
    metastore.api.Table internally.
    
    Tests:
    Ran core tests.
    
    Change-Id: I2dfc54ae2f995dc4ab735d17dbbad9a48f6633da
    Reviewed-on: http://gerrit.cloudera.org:8080/17910
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
    Reviewed-by: Vihang Karajgaonkar <vi...@cloudera.com>
---
 .../org/apache/impala/compat/HiveMetadataFormatUtils.java   | 12 ++++++------
 .../java/org/apache/impala/compat/MetastoreShim.java        | 13 +++++++------
 .../org/apache/impala/service/DescribeResultFactory.java    | 12 ++----------
 3 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/fe/src/compat-hive-3/java/org/apache/impala/compat/HiveMetadataFormatUtils.java b/fe/src/compat-hive-3/java/org/apache/impala/compat/HiveMetadataFormatUtils.java
index a2b1a5e..394366d 100644
--- a/fe/src/compat-hive-3/java/org/apache/impala/compat/HiveMetadataFormatUtils.java
+++ b/fe/src/compat-hive-3/java/org/apache/impala/compat/HiveMetadataFormatUtils.java
@@ -396,19 +396,19 @@ public class HiveMetadataFormatUtils {
     return null;
   }
 
-  public static String getConstraintsInformation(
-      org.apache.hadoop.hive.ql.metadata.Table table) {
+  public static String getConstraintsInformation(PrimaryKeyInfo pkInfo,
+      ForeignKeyInfo fkInfo) {
     StringBuilder constraintsInfo = new StringBuilder(DEFAULT_STRINGBUILDER_SIZE);
 
     constraintsInfo.append(LINE_DELIM).append("# Constraints").append(LINE_DELIM);
 
-    if (PrimaryKeyInfo.isPrimaryKeyInfoNotEmpty(table.getPrimaryKeyInfo())) {
+    if (PrimaryKeyInfo.isPrimaryKeyInfoNotEmpty(pkInfo)) {
       constraintsInfo.append(LINE_DELIM).append("# Primary Key").append(LINE_DELIM);
-      getPrimaryKeyInformation(constraintsInfo, table.getPrimaryKeyInfo());
+      getPrimaryKeyInformation(constraintsInfo, pkInfo);
     }
-    if (ForeignKeyInfo.isForeignKeyInfoNotEmpty(table.getForeignKeyInfo())) {
+    if (ForeignKeyInfo.isForeignKeyInfoNotEmpty(fkInfo)) {
       constraintsInfo.append(LINE_DELIM).append("# Foreign Keys").append(LINE_DELIM);
-      getForeignKeysInformation(constraintsInfo, table.getForeignKeyInfo());
+      getForeignKeysInformation(constraintsInfo, fkInfo);
     }
 
     return constraintsInfo.toString();
diff --git a/fe/src/compat-hive-3/java/org/apache/impala/compat/MetastoreShim.java b/fe/src/compat-hive-3/java/org/apache/impala/compat/MetastoreShim.java
index 86a0c00..5255d7e 100644
--- a/fe/src/compat-hive-3/java/org/apache/impala/compat/MetastoreShim.java
+++ b/fe/src/compat-hive-3/java/org/apache/impala/compat/MetastoreShim.java
@@ -88,6 +88,8 @@ import org.apache.hadoop.hive.metastore.messaging.MessageFactory;
 import org.apache.hadoop.hive.metastore.messaging.MessageSerializer;
 import org.apache.hadoop.hive.metastore.utils.FileUtils;
 import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;
+import org.apache.hadoop.hive.ql.metadata.PrimaryKeyInfo;
+import org.apache.hadoop.hive.ql.metadata.ForeignKeyInfo;
 import org.apache.hive.service.rpc.thrift.TGetColumnsReq;
 import org.apache.hive.service.rpc.thrift.TGetFunctionsReq;
 import org.apache.hive.service.rpc.thrift.TGetSchemasReq;
@@ -481,18 +483,17 @@ public class MetastoreShim {
    * changed significantly in Hive-3
    * @return
    */
-  public static String getTableInformation(
-      org.apache.hadoop.hive.ql.metadata.Table table) {
-    return HiveMetadataFormatUtils.getTableInformation(table.getTTable(), false);
+  public static String getTableInformation(Table table) {
+    return HiveMetadataFormatUtils.getTableInformation(table, false);
   }
 
   /**
    * Wrapper method around Hive-3's MetadataFormatUtils.getConstraintsInformation
    * @return
    */
-  public static String getConstraintsInformation(
-      org.apache.hadoop.hive.ql.metadata.Table table) {
-    return HiveMetadataFormatUtils.getConstraintsInformation(table);
+  public static String getConstraintsInformation(PrimaryKeyInfo pkInfo,
+      ForeignKeyInfo fkInfo) {
+    return HiveMetadataFormatUtils.getConstraintsInformation(pkInfo, fkInfo);
   }
 
   /**
diff --git a/fe/src/main/java/org/apache/impala/service/DescribeResultFactory.java b/fe/src/main/java/org/apache/impala/service/DescribeResultFactory.java
index d809ab4..4cb8629 100644
--- a/fe/src/main/java/org/apache/impala/service/DescribeResultFactory.java
+++ b/fe/src/main/java/org/apache/impala/service/DescribeResultFactory.java
@@ -220,29 +220,21 @@ public class DescribeResultFactory {
     msTable.getSd().setCols(Column.toFieldSchemas(nonClustered));
     msTable.setPartitionKeys(Column.toFieldSchemas(clustered));
 
-    // To avoid initializing any of the SerDe classes in the metastore table Thrift
-    // struct, create the ql.metadata.Table object by calling the empty c'tor and
-    // then calling setTTable().
-    org.apache.hadoop.hive.ql.metadata.Table hiveTable =
-        new org.apache.hadoop.hive.ql.metadata.Table();
-    hiveTable.setTTable(msTable);
     org.apache.hadoop.hive.ql.metadata.PrimaryKeyInfo pki =
         new org.apache.hadoop.hive.ql.metadata.PrimaryKeyInfo(
             table.getSqlConstraints().getPrimaryKeys(), table.getName(),
             table.getDb().getName());
-    hiveTable.setPrimaryKeyInfo(pki);
     org.apache.hadoop.hive.ql.metadata.ForeignKeyInfo fki =
         new org.apache.hadoop.hive.ql.metadata.ForeignKeyInfo(
             table.getSqlConstraints().getForeignKeys(), table.getName(),
             table.getDb().getName());
-    hiveTable.setForeignKeyInfo(fki);
     StringBuilder sb = new StringBuilder();
     // First add all the columns (includes partition columns).
     sb.append(MetastoreShim.getAllColumnsInformation(msTable.getSd().getCols(),
         msTable.getPartitionKeys(), true, false, true));
     // Add the extended table metadata information.
-    sb.append(MetastoreShim.getTableInformation(hiveTable));
-    sb.append(MetastoreShim.getConstraintsInformation(hiveTable));
+    sb.append(MetastoreShim.getTableInformation(msTable));
+    sb.append(MetastoreShim.getConstraintsInformation(pki, fki));
 
     for (String line: sb.toString().split("\n")) {
       // To match Hive's HiveServer2 output, split each line into multiple column