diff --git ql/src/test/org/apache/hadoop/hive/ql/metadata/TestSessionHiveMetastoreClientListPartitionsTempTable.java ql/src/test/org/apache/hadoop/hive/ql/metadata/TestSessionHiveMetastoreClientListPartitionsTempTable.java index 64f7a32ec7..42d1af7d07 100644 --- ql/src/test/org/apache/hadoop/hive/ql/metadata/TestSessionHiveMetastoreClientListPartitionsTempTable.java +++ ql/src/test/org/apache/hadoop/hive/ql/metadata/TestSessionHiveMetastoreClientListPartitionsTempTable.java @@ -212,6 +212,18 @@ public void testListPartitionValuesNullTblName() throws Exception { super.testListPartitionValuesNullTblName(); } + @Test(expected = NoSuchObjectException.class) + @Override + public void testListPartitionNamesNoDb() throws Exception { + super.testListPartitionNamesNoDb(); + } + + @Test + @Override + public void testListPartitionsAllNoTable() throws Exception { + super.testListPartitionsAllNoTable(); + } + @Test public void testListPartitionsByExpr() throws Exception { createTable4PartColsParts(getClient()); @@ -262,19 +274,19 @@ public void testListPartitionsByExprNoDb() throws Exception { null, (short)-1, new ArrayList<>()); } - @Test(expected = NoSuchObjectException.class) + @Test(expected = MetaException.class) public void testListPartitionsByExprNoTbl() throws Exception { getClient().listPartitionsByExpr(DB_NAME, TABLE_NAME, new byte[] {'f', 'o', 'o'}, null, (short)-1, new ArrayList<>()); } - @Test(expected = NoSuchObjectException.class) + @Test(expected = MetaException.class) public void testListPartitionsByExprEmptyDbName() throws Exception { getClient().listPartitionsByExpr("", TABLE_NAME, new byte[] {'f', 'o', 'o'}, null, (short)-1, new ArrayList<>()); } - @Test(expected = NoSuchObjectException.class) + @Test(expected = MetaException.class) public void testListPartitionsByExprEmptyTblName() throws Exception { createTable3PartCols1Part(getClient()); getClient().listPartitionsByExpr(DB_NAME, "", new byte[] {'f', 'o', 'o'}, diff --git standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index 94698e6771..58352905f9 100644 --- standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -71,6 +71,8 @@ import javax.jdo.JDOException; import com.codahale.metrics.Counter; +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.collect.Lists; import org.apache.commons.cli.OptionBuilder; @@ -4979,14 +4981,21 @@ public Partition get_partition(final String db_name, final String tbl_name, private void fireReadTablePreEvent(String catName, String dbName, String tblName) throws MetaException, NoSuchObjectException { if(preListeners.size() > 0) { - // do this only if there is a pre event listener registered (avoid unnecessary - // metastore api call) - Table t = getMS().getTable(catName, dbName, tblName); - if (t == null) { - throw new NoSuchObjectException(TableName.getQualified(catName, dbName, tblName) - + " table not found"); - } - firePreEvent(new PreReadTableEvent(t, this)); + Supplier tableSupplier = Suppliers.memoize(new Supplier
() { + @Override public Table get() { + try { + Table t = getMS().getTable(catName, dbName, tblName); + if (t == null) { + throw new NoSuchObjectException(TableName.getQualified(catName, dbName, tblName) + + " table not found"); + } + return t; + } catch(MetaException | NoSuchObjectException e) { + throw new RuntimeException(e); + } + } + }); + firePreEvent(new PreReadTableEvent(tableSupplier, this)); } } diff --git standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/events/PreReadTableEvent.java standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/events/PreReadTableEvent.java index beec72bc12..c1325773ec 100644 --- standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/events/PreReadTableEvent.java +++ standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/events/PreReadTableEvent.java @@ -18,6 +18,7 @@ package org.apache.hadoop.hive.metastore.events; +import com.google.common.base.Supplier; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.hive.metastore.IHMSHandler; @@ -30,18 +31,23 @@ @InterfaceStability.Stable public class PreReadTableEvent extends PreEventContext { - private final Table table; + private final Supplier
tableSupplier; public PreReadTableEvent(Table table, IHMSHandler handler) { super(PreEventType.READ_TABLE, handler); - this.table = table; + this.tableSupplier = () -> table; + } + + public PreReadTableEvent(Supplier
tableSupplier, IHMSHandler handler) { + super(PreEventType.READ_TABLE, handler); + this.tableSupplier = tableSupplier; } /** * @return the table */ public Table getTable() { - return table; + return tableSupplier.get(); } } diff --git standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java index b7c1d9d952..4508e054dc 100644 --- standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java +++ standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java @@ -2352,7 +2352,7 @@ public void testPartitionFilter() throws Exception { } assertNotNull(me); assertTrue("NoSuchObject exception", me.getMessage().contains( - "invDBName.invTableName table not found")); + "Specified catalog.database.table does not exist : hive.invdbname.invtablename")); client.dropTable(dbName, tblName); client.dropDatabase(dbName); diff --git standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestGetPartitions.java standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestGetPartitions.java index 5d5ff1c2f2..9c565aacfc 100644 --- standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestGetPartitions.java +++ standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestGetPartitions.java @@ -386,12 +386,12 @@ public void testGetPartitionsByNamesNoTblName() throws Exception { client.getPartitionsByNames(DB_NAME, "", Lists.newArrayList("yyyy=2000/mm=01/dd=02")); } - @Test(expected = NoSuchObjectException.class) + @Test(expected = TException.class) public void testGetPartitionsByNamesNoTable() throws Exception { client.getPartitionsByNames(DB_NAME, TABLE_NAME, Lists.newArrayList("yyyy=2000/mm=01/dd=02")); } - @Test(expected = NoSuchObjectException.class) + @Test(expected = TException.class) public void testGetPartitionsByNamesNoDb() throws Exception { client.dropDatabase(DB_NAME); client.getPartitionsByNames(DB_NAME, TABLE_NAME, Lists.newArrayList("yyyy=2000/mm=01/dd=02")); @@ -486,7 +486,8 @@ public void testGetPartitionWithAuthInfoWrongNumOfPartVals() throws Exception { Lists.newArrayList("1997", "05"), "user0", Lists.newArrayList("group0")); } - @Test + @Test(expected = MetaException.class) + // null DB would throw NPE wrapped up in MetaException public void testGetPartitionWithAuthInfoNullDbName() throws Exception { try { createTable3PartCols1PartAuthOn(client); @@ -498,7 +499,8 @@ public void testGetPartitionWithAuthInfoNullDbName() throws Exception { } } - @Test + @Test(expected = MetaException.class) + // null table would throw NPE wrapped up in MetaException public void testGetPartitionWithAuthInfoNullTblName() throws Exception { try { createTable3PartCols1PartAuthOn(client); @@ -607,7 +609,7 @@ public void getPartitionWithAuthBogusCatalog() throws TException { Lists.newArrayList("1997", "05", "16"), "user0", Lists.newArrayList("group0")); } - @Test(expected = NoSuchObjectException.class) + @Test(expected = TException.class) @ConditionalIgnoreOnSessionHiveMetastoreClient public void getPartitionsByNamesBogusCatalog() throws TException { createTable3PartCols1Part(client); diff --git standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestListPartitions.java standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestListPartitions.java index 8d0c095220..242955cf40 100644 --- standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestListPartitions.java +++ standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestListPartitions.java @@ -319,7 +319,7 @@ public void testListPartitionsAllNoTblName() throws Exception { client.listPartitions(DB_NAME, "", (short)-1); } - @Test + @Test(expected = MetaException.class) public void testListPartitionsAllNullTblName() throws Exception { try { createTable3PartCols1Part(client); @@ -330,7 +330,7 @@ public void testListPartitionsAllNullTblName() throws Exception { } } - @Test + @Test(expected = MetaException.class) public void testListPartitionsAllNullDbName() throws Exception { try { createTable3PartCols1Part(client); @@ -706,7 +706,7 @@ public void testListPartitionsWithAuthByValuesNoDb() throws Exception { .newArrayList("2017", "11", "27"), (short)-1, "", Lists.newArrayList()); } - @Test + @Test(expected = MetaException.class) public void testListPartitionsWithAuthByValuesNullDbName() throws Exception { try { createTable4PartColsParts(client); @@ -718,7 +718,7 @@ public void testListPartitionsWithAuthByValuesNullDbName() throws Exception { } } - @Test + @Test(expected = MetaException.class) public void testListPartitionsWithAuthByValuesNullTblName() throws Exception { try { createTable4PartColsParts(client); @@ -895,7 +895,7 @@ public void testListPartitionsByFilterNoDb() throws Exception { client.listPartitionsByFilter(DB_NAME, TABLE_NAME, "yyyy=\"2017\"", (short)-1); } - @Test + @Test(expected = MetaException.class) public void testListPartitionsByFilterNullTblName() throws Exception { try { createTable4PartColsParts(client); @@ -906,7 +906,7 @@ public void testListPartitionsByFilterNullTblName() throws Exception { } } - @Test + @Test(expected = MetaException.class) public void testListPartitionsByFilterNullDbName() throws Exception { try { createTable4PartColsParts(client); @@ -1137,30 +1137,31 @@ public void testListPartitionNames() throws Exception { } - @Test(expected = NoSuchObjectException.class) + @Test(expected = MetaException.class) public void testListPartitionNamesNoDbName() throws Exception { createTable4PartColsParts(client); client.listPartitionNames("", TABLE_NAME, (short)-1); } - @Test(expected = NoSuchObjectException.class) + @Test(expected = MetaException.class) public void testListPartitionNamesNoTblName() throws Exception { createTable4PartColsParts(client); client.listPartitionNames(DB_NAME, "", (short)-1); } - @Test(expected = NoSuchObjectException.class) + @Test public void testListPartitionNamesNoTable() throws Exception { - client.listPartitionNames(DB_NAME, TABLE_NAME, (short)-1); + List names = client.listPartitionNames(DB_NAME, TABLE_NAME, (short)-1); + Assert.assertEquals(0, names.size()); } - @Test(expected = NoSuchObjectException.class) + @Test public void testListPartitionNamesNoDb() throws Exception { client.dropDatabase(DB_NAME); client.listPartitionNames(DB_NAME, TABLE_NAME, (short)-1); } - @Test + @Test(expected = MetaException.class) public void testListPartitionNamesNullDbName() throws Exception { try { createTable4PartColsParts(client); @@ -1171,7 +1172,7 @@ public void testListPartitionNamesNullDbName() throws Exception { } } - @Test + @Test(expected = MetaException.class) public void testListPartitionNamesNullTblName() throws Exception { try { createTable4PartColsParts(client); @@ -1278,7 +1279,7 @@ public void testListPartitionNamesByValuesNoDb() throws Exception { client.listPartitionNames(DB_NAME, TABLE_NAME, Lists.newArrayList("2017"), (short)-1); } - @Test + @Test(expected = MetaException.class) public void testListPartitionNamesByValuesNullDbName() throws Exception { try { createTable4PartColsParts(client); @@ -1289,7 +1290,7 @@ public void testListPartitionNamesByValuesNullDbName() throws Exception { } } - @Test + @Test(expected = MetaException.class) public void testListPartitionNamesByValuesNullTblName() throws Exception { try { createTable4PartColsParts(client); @@ -1560,11 +1561,12 @@ public void getNumPartitionsByFilterBogusCatalog() throws TException { client.getNumPartitionsByFilter("bogus", DB_NAME, TABLE_NAME, "partcol=\"a0\""); } - @Test(expected = NoSuchObjectException.class) + @Test @ConditionalIgnoreOnSessionHiveMetastoreClient public void listPartitionNamesBogusCatalog() throws TException { createTable3PartCols1Part(client); - client.listPartitionNames("bogus", DB_NAME, TABLE_NAME, -1); + List parts = client.listPartitionNames("bogus", DB_NAME, TABLE_NAME, -1); + Assert.assertEquals(0, parts.size()); } @Test(expected = NoSuchObjectException.class)