deniskuzZ commented on code in PR #6961: URL: https://github.com/apache/hive/pull/6961#discussion_r4669982421
##########
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:
This replays the Executor steps by hand, so it passes even if
Executor.execute changes.
Could it be a Driver test in its own class instead (HiveConfForTest, a
post-exec hook that calls getTable(db, tbl, false), create table if not
exists)? That covers the real code path. getTable(db, tbl) throws on a miss, so
the hook needs the false variant for assertNotNull to be the actual check.
##########
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:
````
public class TestExecutorHMSQueryCache {
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 org.apache.hadoop.hive.ql.metadata.Table found;
@Override
public void run(HookContext hookContext) throws Exception {
found = Hive.get().getTable("default", TABLE, false);
}
}
private IDriver driver;
@Before
public void setUp() {
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);
LookupCreatedTableHook.found = null;
}
@After
public void tearDown() throws Exception {
driver.run("drop table if exists " + TABLE);
driver.close();
SessionState.get().close();
}
@Test
public void testPostExecHookFindsTableCreatedByQuery() throws Exception
{
// 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("a post-execution hook sees the table the query
created", LookupCreatedTableHook.found);
}
}
````
--
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]
