[ 
https://issues.apache.org/jira/browse/HIVE-22782?focusedWorklogId=483645&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-483645
 ]

ASF GitHub Bot logged work on HIVE-22782:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 13/Sep/20 14:53
            Start Date: 13/Sep/20 14:53
    Worklog Time Spent: 10m 
      Work Description: sankarh commented on a change in pull request #1419:
URL: https://github.com/apache/hive/pull/1419#discussion_r487538671



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java
##########
@@ -5661,184 +5664,69 @@ public void dropConstraint(String dbName, String 
tableName, String constraintNam
     }
   }
 
-  public List<SQLDefaultConstraint> getDefaultConstraintList(String dbName, 
String tblName) throws HiveException, NoSuchObjectException {
-    try {
-      return getMSC().getDefaultConstraints(new 
DefaultConstraintsRequest(getDefaultCatalog(conf), dbName, tblName));
-    } catch (NoSuchObjectException e) {
-      throw e;
-    } catch (Exception e) {
-      throw new HiveException(e);
-    }
-  }
-
-  public List<SQLCheckConstraint> getCheckConstraintList(String dbName, String 
tblName) throws HiveException, NoSuchObjectException {
+  public SQLAllTableConstraints getTableConstraints(String dbName, String 
tblName)
+      throws HiveException, NoSuchObjectException {
     try {
-      return getMSC().getCheckConstraints(new 
CheckConstraintsRequest(getDefaultCatalog(conf),
-          dbName, tblName));
+      return getMSC().getAllTableConstraints(new 
AllTableConstraintsRequest(dbName, tblName, getDefaultCatalog(conf)));
     } catch (NoSuchObjectException e) {

Review comment:
       Will NoSuchObjectException comes here? From the interface, it sounds not.

##########
File path: ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java
##########
@@ -5661,184 +5663,79 @@ public void dropConstraint(String dbName, String 
tableName, String constraintNam
     }
   }
 
-  public List<SQLDefaultConstraint> getDefaultConstraintList(String dbName, 
String tblName) throws HiveException, NoSuchObjectException {
+  public SQLAllTableConstraints getTableConstraints(String dbName, String 
tblName) throws HiveException, NoSuchObjectException {
     try {
-      return getMSC().getDefaultConstraints(new 
DefaultConstraintsRequest(getDefaultCatalog(conf), dbName, tblName));
+      AllTableConstraintsRequest tableConstraintsRequest = new 
AllTableConstraintsRequest();
+      tableConstraintsRequest.setDbName(dbName);
+      tableConstraintsRequest.setTblName(tblName);
+      tableConstraintsRequest.setCatName(getDefaultCatalog(conf));
+      return getMSC().getAllTableConstraints(tableConstraintsRequest);
     } catch (NoSuchObjectException e) {
       throw e;
     } catch (Exception e) {
       throw new HiveException(e);
     }
   }
-
-  public List<SQLCheckConstraint> getCheckConstraintList(String dbName, String 
tblName) throws HiveException, NoSuchObjectException {
-    try {
-      return getMSC().getCheckConstraints(new 
CheckConstraintsRequest(getDefaultCatalog(conf),
-          dbName, tblName));
-    } catch (NoSuchObjectException e) {
-      throw e;
-    } catch (Exception e) {
-      throw new HiveException(e);
-    }
+  public TableConstraintsInfo getAllTableConstraints(String dbName, String 
tblName) throws HiveException {
+    return getTableConstraints(dbName, tblName, false, false);
   }
 
-  /**
-   * Get all primary key columns associated with the table.
-   *
-   * @param dbName Database Name
-   * @param tblName Table Name
-   * @return Primary Key associated with the table.
-   * @throws HiveException
-   */
-  public PrimaryKeyInfo getPrimaryKeys(String dbName, String tblName) throws 
HiveException {
-    return getPrimaryKeys(dbName, tblName, false);
+  public TableConstraintsInfo getReliableAndEnableTableConstraints(String 
dbName, String tblName) throws HiveException {
+    return getTableConstraints(dbName, tblName, true, true);
   }
 
-  /**
-   * Get primary key columns associated with the table that are available for 
optimization.
-   *
-   * @param dbName Database Name
-   * @param tblName Table Name
-   * @return Primary Key associated with the table.
-   * @throws HiveException
-   */
-  public PrimaryKeyInfo getReliablePrimaryKeys(String dbName, String tblName) 
throws HiveException {
-    return getPrimaryKeys(dbName, tblName, true);
-  }
-
-  private PrimaryKeyInfo getPrimaryKeys(String dbName, String tblName, boolean 
onlyReliable)
+  private TableConstraintsInfo getTableConstraints(String dbName, String 
tblName, boolean reliable, boolean enable)
       throws HiveException {
     PerfLogger perfLogger = SessionState.getPerfLogger();
-    perfLogger.perfLogBegin(CLASS_NAME, PerfLogger.HIVE_GET_PK);
-    try {
-      List<SQLPrimaryKey> primaryKeys = getMSC().getPrimaryKeys(new 
PrimaryKeysRequest(dbName, tblName));
-      if (onlyReliable && primaryKeys != null && !primaryKeys.isEmpty()) {
-        primaryKeys = primaryKeys.stream()
-          .filter(pk -> pk.isRely_cstr())
-          .collect(Collectors.toList());
-      }
-
-      return new PrimaryKeyInfo(primaryKeys, tblName, dbName);
-    } catch (Exception e) {
-      throw new HiveException(e);
-    } finally {
-      perfLogger.perfLogEnd(CLASS_NAME, PerfLogger.HIVE_GET_PK, "HS2-cache");
-    }
-  }
-
-  /**
-   * Get all foreign keys associated with the table.
-   *
-   * @param dbName Database Name
-   * @param tblName Table Name
-   * @return Foreign keys associated with the table.
-   * @throws HiveException
-   */
-  public ForeignKeyInfo getForeignKeys(String dbName, String tblName) throws 
HiveException {
-    return getForeignKeys(dbName, tblName, false);
-  }
-
-  /**
-   * Get foreign keys associated with the table that are available for 
optimization.
-   *
-   * @param dbName Database Name
-   * @param tblName Table Name
-   * @return Foreign keys associated with the table.
-   * @throws HiveException
-   */
-  public ForeignKeyInfo getReliableForeignKeys(String dbName, String tblName) 
throws HiveException {
-    return getForeignKeys(dbName, tblName, true);
-  }
-
-  private ForeignKeyInfo getForeignKeys(String dbName, String tblName, boolean 
onlyReliable)
-      throws HiveException {
-    PerfLogger perfLogger = SessionState.getPerfLogger();
-    perfLogger.perfLogBegin(CLASS_NAME, PerfLogger.HIVE_GET_FK);
-    try {
-      List<SQLForeignKey> foreignKeys = getMSC().getForeignKeys(new 
ForeignKeysRequest(null, null, dbName, tblName));
-      if (onlyReliable && foreignKeys != null && !foreignKeys.isEmpty()) {
-        foreignKeys = foreignKeys.stream()
-          .filter(fk -> fk.isRely_cstr())
-          .collect(Collectors.toList());
+    perfLogger.perfLogBegin(CLASS_NAME, PerfLogger.HIVE_GET_TABLE_CONSTRAINTS);
+    try {
+      SQLAllTableConstraints tableConstraints =
+          getMSC().getAllTableConstraints(new 
AllTableConstraintsRequest(dbName, tblName));
+      if (reliable && tableConstraints != null) {
+        if (tableConstraints.getPrimaryKeys() != null && 
!tableConstraints.getPrimaryKeys().isEmpty()) {
+          tableConstraints.setPrimaryKeys(
+              tableConstraints.getPrimaryKeys().stream().filter(primaryKey -> 
primaryKey.isRely_cstr())
+                  .collect(Collectors.toList()));
+        }
+        if (tableConstraints.getForeignKeys() != null && 
!tableConstraints.getForeignKeys().isEmpty()) {
+          tableConstraints.setForeignKeys(
+              tableConstraints.getForeignKeys().stream().filter(foreignKey -> 
foreignKey.isRely_cstr())
+                  .collect(Collectors.toList()));
+        }
+        if (tableConstraints.getUniqueConstraints() != null && 
!tableConstraints.getUniqueConstraints().isEmpty()) {
+          
tableConstraints.setUniqueConstraints(tableConstraints.getUniqueConstraints().stream()
+              .filter(uniqueConstraint -> 
uniqueConstraint.isRely_cstr()).collect(Collectors.toList()));
+        }
+        if (tableConstraints.getNotNullConstraints() != null && 
!tableConstraints.getNotNullConstraints().isEmpty()) {
+          
tableConstraints.setNotNullConstraints(tableConstraints.getNotNullConstraints().stream()
+              .filter(notNullConstraint -> 
notNullConstraint.isRely_cstr()).collect(Collectors.toList()));
+        }
       }
 
-      return new ForeignKeyInfo(foreignKeys, tblName, dbName);
-    } catch (Exception e) {
-      throw new HiveException(e);
-    } finally {
-      perfLogger.perfLogEnd(CLASS_NAME, PerfLogger.HIVE_GET_FK, "HS2-cache");
-    }
-  }
-
-  /**
-   * Get all unique constraints associated with the table.
-   *
-   * @param dbName Database Name
-   * @param tblName Table Name
-   * @return Unique constraints associated with the table.
-   * @throws HiveException
-   */
-  public UniqueConstraint getUniqueConstraints(String dbName, String tblName) 
throws HiveException {
-    return getUniqueConstraints(dbName, tblName, false);
-  }
-
-  /**
-   * Get unique constraints associated with the table that are available for 
optimization.
-   *
-   * @param dbName Database Name
-   * @param tblName Table Name
-   * @return Unique constraints associated with the table.
-   * @throws HiveException
-   */
-  public UniqueConstraint getReliableUniqueConstraints(String dbName, String 
tblName) throws HiveException {
-    return getUniqueConstraints(dbName, tblName, true);
-  }
-
-  private UniqueConstraint getUniqueConstraints(String dbName, String tblName, 
boolean onlyReliable)
-      throws HiveException {
-    PerfLogger perfLogger = SessionState.getPerfLogger();
-    perfLogger.perfLogBegin(CLASS_NAME, PerfLogger.HIVE_GET_UNIQ_CONSTRAINT);
-    try {
-      List<SQLUniqueConstraint> uniqueConstraints = 
getMSC().getUniqueConstraints(
-              new UniqueConstraintsRequest(getDefaultCatalog(conf), dbName, 
tblName));
-      if (onlyReliable && uniqueConstraints != null && 
!uniqueConstraints.isEmpty()) {
-        uniqueConstraints = uniqueConstraints.stream()
-          .filter(uk -> uk.isRely_cstr())
-          .collect(Collectors.toList());
+      if (enable && tableConstraints != null) {

Review comment:
       ok




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 483645)
    Time Spent: 5h 40m  (was: 5.5h)

> Consolidate metastore call to fetch constraints
> -----------------------------------------------
>
>                 Key: HIVE-22782
>                 URL: https://issues.apache.org/jira/browse/HIVE-22782
>             Project: Hive
>          Issue Type: Improvement
>          Components: Query Planning
>            Reporter: Vineet Garg
>            Assignee: Ashish Sharma
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 5h 40m
>  Remaining Estimate: 0h
>
> Currently separate calls are made to metastore to fetch constraints like Pk, 
> fk, not null etc. Since planner always retrieve these constraints we should 
> retrieve all of them in one call.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to