deniskuzZ commented on code in PR #6961:
URL: https://github.com/apache/hive/pull/6961#discussion_r4669987903
##########
ql/src/test/org/apache/hadoop/hive/ql/metadata/TestSessionHiveMetaStoreClientQueryCache.java:
##########
@@ -201,6 +202,35 @@ public void testMissingTableLookedUpOncePerQuery() throws
Exception {
verify(delegate, times(2)).getTable(any(GetTableRequest.class));
}
+ @Test
+ public void testMissingTableLookedUpAgainAfterExecution() throws Exception {
+ String queryId = "test_missing_table_after_execution";
+ HiveConf conf = startQuery(queryId);
+ IMetaStoreClient delegate = tableDelegate();
+ // CTAS: the target is missing at compile time, then created by a task
while the cache is disabled
+ when(delegate.getTable(any(GetTableRequest.class)))
+ .thenThrow(new NoSuchObjectException("db.t not found"))
+ .thenReturn(new Table());
+ SessionHiveMetaStoreClient client =
SessionHiveMetaStoreClient.newClient(conf, delegate);
+
+ try {
+ client.getTable(hiveGetTableRequest());
+ fail("table should not be found");
+ } catch (NoSuchObjectException e) {
+ // compile time: the target does not exist yet
+ }
+
+ // as Executor.execute does around runTasks
Review Comment:
````
package org.apache.hadoop.hive.ql.hooks;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.conf.HiveConfForTest;
import org.apache.hadoop.hive.ql.Driver;
import org.apache.hadoop.hive.ql.metadata.Hive;
import org.apache.hadoop.hive.ql.metadata.Table;
import org.apache.hadoop.hive.ql.session.SessionState;
import org.junit.After;
import org.junit.Test;
public class TestQueryCacheTableNotFound {
private static final String TABLE = "query_cache_created_table";
/** Looks up the created table by name, as a post-execution hook would. */
public static class LookupCreatedTableHook implements
ExecuteWithHookContext {
static Table found;
@Override
public void run(HookContext hookContext) throws Exception {
found = Hive.get().getTable("default", TABLE);
}
}
private Driver driver;
@After
public void tearDown() throws Exception {
driver.run("drop table if exists " + TABLE);
}
@Test
public void testPostExecHookFindsTableCreatedByQuery() throws Exception {
HiveConf conf = new HiveConfForTest(getClass());
conf.setBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, false);
conf.setBoolVar(HiveConf.ConfVars.HIVE_OPTIMIZE_HMS_QUERY_CACHE_ENABLED,
true);
conf.setVar(HiveConf.ConfVars.POST_EXEC_HOOKS,
LookupCreatedTableHook.class.getName());
SessionState.start(conf);
driver = new Driver(conf);
// IF NOT EXISTS: the analyzer looks the table up at compile time and
caches it as not found
driver.run("create table if not exists " + TABLE + " (i int)");
assertNotNull(LookupCreatedTableHook.found);
assertEquals(TABLE, LookupCreatedTableHook.found.getTableName());
}
}
````
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]