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

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

                Author: ASF GitHub Bot
            Created on: 26/Aug/20 07:55
            Start Date: 26/Aug/20 07:55
    Worklog Time Spent: 10m 
      Work Description: ashish-kumar-sharma commented on a change in pull 
request #1419:
URL: https://github.com/apache/hive/pull/1419#discussion_r477106020



##########
File path: 
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestGetAllTableConstraints.java
##########
@@ -0,0 +1,145 @@
+package org.apache.hadoop.hive.metastore.client;
+
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.MetaStoreTestUtils;
+import org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest;
+import org.apache.hadoop.hive.metastore.api.AllTableConstraintsRequest;
+import org.apache.hadoop.hive.metastore.api.Catalog;
+import org.apache.hadoop.hive.metastore.api.Database;
+import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.apache.hadoop.hive.metastore.api.PrimaryKeysRequest;
+import org.apache.hadoop.hive.metastore.api.SQLAllTableConstraints;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.metastore.client.builder.CatalogBuilder;
+import org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder;
+import org.apache.hadoop.hive.metastore.client.builder.TableBuilder;
+import org.apache.hadoop.hive.metastore.minihms.AbstractMetaStoreService;
+import org.apache.thrift.TException;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static org.apache.hadoop.hive.metastore.Warehouse.DEFAULT_DATABASE_NAME;
+
+@RunWith(Parameterized.class)
+@Category(MetastoreCheckinTest.class)
+public class TestGetAllTableConstraints extends MetaStoreClientTest {
+  private static final String OTHER_DATABASE = 
"test_constraints_other_database";
+  private static final String OTHER_CATALOG = "test_constraints_other_catalog";
+  private static final String DATABASE_IN_OTHER_CATALOG = 
"test_constraints_database_in_other_catalog";
+  private final AbstractMetaStoreService metaStore;
+  private IMetaStoreClient client;
+  private Table[] testTables = new Table[3];
+  private Database inOtherCatalog;
+
+  public TestGetAllTableConstraints(String name, AbstractMetaStoreService 
metaStore) throws Exception {
+    this.metaStore = metaStore;
+  }
+  @Before
+  public void setUp() throws Exception {
+    // Get new client
+    client = metaStore.getClient();
+
+    // Clean up the database
+    client.dropDatabase(OTHER_DATABASE, true, true, true);
+    // Drop every table in the default database
+    for(String tableName : client.getAllTables(DEFAULT_DATABASE_NAME)) {
+      client.dropTable(DEFAULT_DATABASE_NAME, tableName, true, true, true);
+    }
+
+    client.dropDatabase(OTHER_CATALOG, DATABASE_IN_OTHER_CATALOG, true, true, 
true);
+    try {
+      client.dropCatalog(OTHER_CATALOG);
+    } catch (NoSuchObjectException e) {
+      // NOP
+    }
+
+    // Clean up trash
+    metaStore.cleanWarehouseDirs();
+
+    new DatabaseBuilder().setName(OTHER_DATABASE).create(client, 
metaStore.getConf());
+
+    Catalog cat = new CatalogBuilder()
+        .setName(OTHER_CATALOG)
+        .setLocation(MetaStoreTestUtils.getTestWarehouseDir(OTHER_CATALOG))
+        .build();
+    client.createCatalog(cat);
+
+    // For this one don't specify a location to make sure it gets put in the 
catalog directory
+    inOtherCatalog = new DatabaseBuilder()
+        .setName(DATABASE_IN_OTHER_CATALOG)
+        .setCatalogName(OTHER_CATALOG)
+        .create(client, metaStore.getConf());
+
+    testTables[0] =
+        new TableBuilder()
+            .setTableName("test_table_1")
+            .addCol("col1", "int")
+            .addCol("col2", "varchar(32)")
+            .create(client, metaStore.getConf());
+
+    testTables[1] =
+        new TableBuilder()
+            .setDbName(OTHER_DATABASE)
+            .setTableName("test_table_2")
+            .addCol("col1", "int")
+            .addCol("col2", "varchar(32)")
+            .create(client, metaStore.getConf());
+
+    testTables[2] =
+        new TableBuilder()
+            .inDb(inOtherCatalog)
+            .setTableName("test_table_3")
+            .addCol("col1", "int")
+            .addCol("col2", "varchar(32)")
+            .create(client, metaStore.getConf());
+
+    // Reload tables from the MetaStore
+    for(int i=0; i < testTables.length; i++) {
+      testTables[i] = client.getTable(testTables[i].getCatName(), 
testTables[i].getDbName(),
+          testTables[i].getTableName());
+    }
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    try {
+      if (client != null) {
+        try {
+          client.close();
+        } catch (Exception e) {
+          // HIVE-19729: Shallow the exceptions based on the discussion in the 
Jira
+        }
+      }
+    } finally {
+      client = null;
+    }
+  }
+
+
+  @Test
+  public void NoConstraints() throws TException{
+    Table table = testTables[0];
+
+    // Make sure get on a table with no key returns empty list
+    PrimaryKeysRequest rqst =
+        new PrimaryKeysRequest(table.getDbName(), table.getTableName());
+    AllTableConstraintsRequest request = new 
AllTableConstraintsRequest(table.getDbName(),table.getTableName());
+
+    request.setCatName(table.getCatName());
+    rqst.setCatName(table.getCatName());
+    SQLAllTableConstraints fetched = client.getAllTableConstraints(request);
+
+    Assert.assertTrue(fetched.getCheckConstraints().isEmpty());
+    Assert.assertTrue(fetched.getForeignKeys().isEmpty());
+    Assert.assertTrue(fetched.getDefaultConstraints().isEmpty());
+    Assert.assertTrue(fetched.getNotNullConstraints().isEmpty());
+    Assert.assertTrue(fetched.getPrimaryKeys().isEmpty());
+    Assert.assertTrue(fetched.getUniqueConstraints().isEmpty());
+  }
+

Review comment:
       Test added




----------------------------------------------------------------
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: 474718)
    Time Spent: 1h  (was: 50m)

> 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: 1h
>  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