You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by jr...@apache.org on 2017/05/24 21:58:25 UTC

[2/2] incubator-impala git commit: IMPALA-5342: Add comments of loaded tables in the response of GetTables

IMPALA-5342: Add comments of loaded tables in the response of GetTables

This commit changes the response of HiveServer2 GetTables request to
return the comments (if any) of loaded tables. For unloaded tables
or for tables with no comments an empty string is returned.

Testing:
- Added a new Frontend test.

Change-Id: I61f327168a93ceb4bd60b47474f39bfa405ae07d
Reviewed-on: http://gerrit.cloudera.org:8080/6933
Reviewed-by: Dimitris Tsirogiannis <dt...@cloudera.com>
Tested-by: Impala Public Jenkins


Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/7191e1b2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/7191e1b2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/7191e1b2

Branch: refs/heads/master
Commit: 7191e1b28ff450aba91d46a1001323a873bbf548
Parents: 2bde3a4
Author: Dimitris Tsirogiannis <dt...@cloudera.com>
Authored: Fri May 19 14:44:33 2017 -0700
Committer: Impala Public Jenkins <im...@gerrit.cloudera.org>
Committed: Wed May 24 20:37:07 2017 +0000

----------------------------------------------------------------------
 .../org/apache/impala/service/MetadataOp.java   | 12 +++++-
 .../org/apache/impala/service/FrontendTest.java | 42 ++++++++++++++++++--
 2 files changed, 48 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/7191e1b2/fe/src/main/java/org/apache/impala/service/MetadataOp.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/service/MetadataOp.java b/fe/src/main/java/org/apache/impala/service/MetadataOp.java
index 78cb785..3bf7534 100644
--- a/fe/src/main/java/org/apache/impala/service/MetadataOp.java
+++ b/fe/src/main/java/org/apache/impala/service/MetadataOp.java
@@ -43,6 +43,7 @@ import org.apache.impala.thrift.TResultRow;
 import org.apache.impala.thrift.TResultSet;
 import org.apache.impala.thrift.TResultSetMetadata;
 import org.apache.impala.util.PatternMatcher;
+import com.google.common.base.Strings;
 import com.google.common.collect.Lists;
 
 /**
@@ -214,6 +215,9 @@ public class MetadataOp {
     // tableNames[i] are the tables within dbs[i]
     public List<List<String>> tableNames = Lists.newArrayList();
 
+    // comments[i][j] is the comment of tableNames[j] in dbs[i].
+    public List<List<String>> comments = Lists.newArrayList();
+
     // columns[i][j] are the columns of tableNames[j] in dbs[i].
     // If the table is missing (not yet loaded) its column list will be empty.
     public List<List<List<Column>>> columns = Lists.newArrayList();
@@ -266,6 +270,7 @@ public class MetadataOp {
         // Get table metadata
         List<String> tableList = Lists.newArrayList();
         List<List<Column>> tablesColumnsList = Lists.newArrayList();
+        List<String> tableComments = Lists.newArrayList();
         for (String tabName: fe.getTableNames(db.getName(), tablePatternMatcher, user)) {
           tableList.add(tabName);
           Table table = null;
@@ -276,18 +281,22 @@ public class MetadataOp {
           }
           if (table == null) continue;
 
+          String comment = null;
           List<Column> columns = Lists.newArrayList();
           // If the table is not yet loaded, the columns will be unknown. Add it
           // to the set of missing tables.
           if (!table.isLoaded()) {
             result.missingTbls.add(new TableName(db.getName(), tabName));
           } else {
+            comment = table.getMetaStoreTable().getParameters().get("comment");
             columns.addAll(fe.getColumns(table, columnPatternMatcher, user));
           }
           tablesColumnsList.add(columns);
+          tableComments.add(Strings.nullToEmpty(comment));
         }
         result.dbs.add(db.getName());
         result.tableNames.add(tableList);
+        result.comments.add(tableComments);
         result.columns.add(tablesColumnsList);
       }
     }
@@ -478,8 +487,7 @@ public class MetadataOp {
         row.colVals.add(createTColumnValue(dbName));
         row.colVals.add(createTColumnValue(tabName));
         row.colVals.add(TABLE_TYPE_COL_VAL);
-        // TODO: Return table comments when it is available in the Impala catalog.
-        row.colVals.add(EMPTY_COL_VAL);
+        row.colVals.add(createTColumnValue(dbsMetadata.comments.get(i).get(j)));
         result.rows.add(row);
       }
     }

http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/7191e1b2/fe/src/test/java/org/apache/impala/service/FrontendTest.java
----------------------------------------------------------------------
diff --git a/fe/src/test/java/org/apache/impala/service/FrontendTest.java b/fe/src/test/java/org/apache/impala/service/FrontendTest.java
index dbd35b3..c3faa0a 100644
--- a/fe/src/test/java/org/apache/impala/service/FrontendTest.java
+++ b/fe/src/test/java/org/apache/impala/service/FrontendTest.java
@@ -18,6 +18,7 @@
 package org.apache.impala.service;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -34,9 +35,12 @@ import org.apache.hive.service.rpc.thrift.TGetTablesReq;
 import org.junit.Test;
 import org.apache.impala.analysis.AuthorizationTest;
 import org.apache.impala.authorization.AuthorizationConfig;
+import org.apache.impala.catalog.Db;
 import org.apache.impala.catalog.Catalog;
 import org.apache.impala.catalog.PrimitiveType;
+import org.apache.impala.catalog.Table;
 import org.apache.impala.common.AnalysisException;
+import org.apache.impala.common.FrontendTestBase;
 import org.apache.impala.common.ImpalaException;
 import org.apache.impala.testutil.ImpaladTestCatalog;
 import org.apache.impala.testutil.TestUtils;
@@ -60,9 +64,7 @@ import com.google.common.collect.Sets;
  * result set.
  *
  */
-public class FrontendTest {
-  private static Frontend fe_ = new Frontend(
-      AuthorizationConfig.createAuthDisabledConfig(), new ImpaladTestCatalog());
+public class FrontendTest extends FrontendTestBase {
 
   @Test
   public void TestCatalogReadiness() throws ImpalaException {
@@ -176,6 +178,38 @@ public class FrontendTest {
   }
 
   @Test
+  public void TestGetTablesWithComments() throws ImpalaException {
+    // Add test db and test tables with comments
+    final String dbName = "tbls_with_comments_test_db";
+    Db testDb = addTestDb(dbName, "Stores tables with comments");
+    assertNotNull(testDb);
+    final String commentStr = "this table has a comment";
+    final String tableWithCommentsStmt = String.format(
+        "create table %s.tbl_with_comments (a int) comment '%s'", dbName, commentStr);
+    Table tbl = addTestTable(tableWithCommentsStmt);
+    assertNotNull(tbl);
+    final String tableWithoutCommentsStmt = String.format(
+        "create table %s.tbl_without_comments (a int)", dbName);
+    tbl = addTestTable(tableWithoutCommentsStmt);
+    assertNotNull(tbl);
+
+    // Prepare and perform the GetTables request
+    TMetadataOpRequest req = new TMetadataOpRequest();
+    req.opcode = TMetadataOpcode.GET_TABLES;
+    req.get_tables_req = new TGetTablesReq();
+    req.get_tables_req.setSchemaName(dbName);
+    TResultSet resp = execMetadataOp(req);
+    assertEquals(2, resp.rows.size());
+    for (TResultRow row: resp.rows) {
+      if (row.colVals.get(2).string_val.toLowerCase().equals("tbl_with_comments")) {
+        assertEquals(commentStr, row.colVals.get(4).string_val.toLowerCase());
+      } else {
+        assertEquals("", row.colVals.get(4).string_val);
+      }
+    }
+  }
+
+  @Test
   public void TestGetColumns() throws ImpalaException {
     // It should return one column: default.alltypes.string_col
     TMetadataOpRequest req = new TMetadataOpRequest();
@@ -255,6 +289,6 @@ public class FrontendTest {
 
   private TResultSet execMetadataOp(TMetadataOpRequest req)
       throws ImpalaException {
-    return fe_.execHiveServer2MetadataOp(req);
+    return frontend_.execHiveServer2MetadataOp(req);
   }
 }