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

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

                Author: ASF GitHub Bot
            Created on: 02/Dec/20 04:18
            Start Date: 02/Dec/20 04:18
    Worklog Time Spent: 10m 
      Work Description: nrg4878 commented on a change in pull request #1681:
URL: https://github.com/apache/hive/pull/1681#discussion_r533886236



##########
File path: 
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
##########
@@ -1855,43 +1869,89 @@ private MTable getMTable(String catName, String db, 
String table) {
       for (String t : tbl_names) {
         lowered_tbl_names.add(normalizeIdentifier(t));
       }
+
       query = pm.newQuery(MTable.class);
       query.setFilter("database.name == db && database.catalogName == cat && 
tbl_names.contains(tableName)");
       query.declareParameters("java.lang.String db, java.lang.String cat, 
java.util.Collection tbl_names");
-      Collection mtables = (Collection) query.execute(db, catName, 
lowered_tbl_names);
-      if (mtables == null || mtables.isEmpty()) {
-        // Need to differentiate between an unmatched pattern and a 
non-existent database
-        dbExistsQuery = pm.newQuery(MDatabase.class, "name == db && 
catalogName == cat");
-        dbExistsQuery.declareParameters("java.lang.String db, java.lang.String 
cat");
-        dbExistsQuery.setUnique(true);
-        dbExistsQuery.setResult("name");
-        String dbNameIfExists = (String) dbExistsQuery.execute(db, catName);
-        if (org.apache.commons.lang3.StringUtils.isEmpty(dbNameIfExists)) {
-          throw new UnknownDBException("Could not find database " +
-              DatabaseName.getQualified(catName, db));
+
+      List<String> projectionFields = null;
+
+      // If a projection specification has been set, validate it and translate 
it to JDO columns.
+      if (projectionSpec != null) {
+        //Validate the projection fields for multi-valued fields.
+        projectionFields = 
TableFields.getMFieldNames(projectionSpec.getFieldList());
+      }
+
+      // If the JDO translation resulted in valid JDO columns names, use it to 
create a projection for the JDO query.
+      if (projectionFields != null) {
+        // fetch partially filled tables using result clause
+        query.setResult(Joiner.on(',').join(projectionFields));
+      }
+
+      if (projectionFields == null) {
+        mtables = (List<MTable>) query.execute(db, catName, lowered_tbl_names);
+      } else {
+        if (projectionFields.size() > 1) {
+          // Execute the query to fetch the partial results.
+          List<Object[]> results = (List<Object[]>) query.execute(db, catName, 
lowered_tbl_names);
+          // Declare the tables array to return the list of tables
+          mtables = new ArrayList<>(results.size());
+          // Iterate through each row of the result and create the MTable 
object.
+          for (Object[] row : results) {
+            MTable mtable = new MTable();
+            int i = 0;
+            for (Object val : row) {
+              MetaStoreServerUtils.setNestedProperty(mtable, 
projectionFields.get(i), val, true);
+              i++;
+            }
+            mtables.add(mtable);
+          }
+        } else if (projectionFields.size() == 1) {
+          // Execute the query to fetch the partial results.
+          List<Object> results = (List<Object>) query.execute(db, catName, 
lowered_tbl_names);
+          // Iterate through each row of the result and create the MTable 
object.
+          mtables = new ArrayList<>(results.size());
+          for (Object row : results) {
+            MTable mtable = new MTable();
+            MetaStoreServerUtils.setNestedProperty(mtable, 
projectionFields.get(0), row, true);
+            mtables.add(mtable);
+          }
         }
+      }
+
+      if (mtables == null || mtables.isEmpty()) {
+        verifyDBExists(catName, db);

Review comment:
       feels like we should just call getDatabaseInternal() and remove this 
refactored code verifyDBExists() code altogether. verifyDBExists() only fetches 
a single column (dbName) in a resultset of 1 row if the DB exists where as 
getDatabaseInternal() fetches few additional columns in a resultset of 1 row. I 
dont think it would be a huge performance degradation but the code will be bit 
cleaner. What do you think?




----------------------------------------------------------------
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:
[email protected]


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

    Worklog Id:     (was: 518760)
    Time Spent: 1h 20m  (was: 1h 10m)

> Add the projection specification to the table request object and add 
> placeholders in ObjectStore.java
> -----------------------------------------------------------------------------------------------------
>
>                 Key: HIVE-24397
>                 URL: https://issues.apache.org/jira/browse/HIVE-24397
>             Project: Hive
>          Issue Type: Sub-task
>          Components: Hive
>            Reporter: Narayanan Venkateswaran
>            Assignee: Narayanan Venkateswaran
>            Priority: Minor
>              Labels: pull-request-available
>          Time Spent: 1h 20m
>  Remaining Estimate: 0h
>




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

Reply via email to