use of org.apache.hive.service.cli.OperationHandle in project hive by apache.
the class ThriftCLIServiceClient method getTypeInfo.
/* (non-Javadoc)
* @see org.apache.hive.service.cli.ICLIService#getTypeInfo(org.apache.hive.service.cli.SessionHandle)
*/
@Override
public OperationHandle getTypeInfo(SessionHandle sessionHandle) throws HiveSQLException {
try {
TGetTypeInfoReq req = new TGetTypeInfoReq(sessionHandle.toTSessionHandle());
TGetTypeInfoResp resp = cliService.GetTypeInfo(req);
checkStatus(resp.getStatus());
TProtocolVersion protocol = sessionHandle.getProtocolVersion();
return new OperationHandle(resp.getOperationHandle(), protocol);
} catch (HiveSQLException e) {
throw e;
} catch (Exception e) {
throw new HiveSQLException(e);
}
}
use of org.apache.hive.service.cli.OperationHandle in project hive by apache.
the class TestHS2HttpServer method testApiServletHistoricalQueries.
@Test
public void testApiServletHistoricalQueries() throws Exception {
String historicalQueriesRoute = "/queries/historical";
final SessionHandle handle = sm.openSession(TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9, "user", "passw", "127.0.0.1", new HashMap());
String queryString = "SET " + HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname + " = false";
OperationHandle opHandle = client.executeStatement(handle, queryString, new HashMap());
client.closeOperation(opHandle);
opHandle = client.executeStatement(handle, "SELECT 1", new HashMap());
client.closeOperation(opHandle);
String queriesResponse = readFromUrl(apiBaseURL + historicalQueriesRoute);
List<JsonNode> historicalQueries = getListOfNodes(queriesResponse);
Assert.assertTrue(historicalQueries.size() == 1);
JsonNode historicalQuery = historicalQueries.get(0);
Assert.assertEquals(historicalQuery.path("running").asBoolean(), false);
Assert.assertEquals(historicalQuery.path("state").asText(), "FINISHED");
Assert.assertTrue(historicalQuery.path("runtime").canConvertToInt());
Assert.assertTrue(historicalQuery.path("queryDisplay").isObject());
}
use of org.apache.hive.service.cli.OperationHandle in project hive by apache.
the class TestOperationLogManager method testOperationLogManager.
@Test
public void testOperationLogManager() throws Exception {
MyThriftBinaryCLIService service = new MyThriftBinaryCLIService();
service.init(hiveConf);
ThriftCLIServiceClient client = new ThriftCLIServiceClient(service);
SessionManager sessionManager = ((CLIService) service.getService()).getSessionManager();
SessionHandle session1 = client.openSession("user1", "foobar", Collections.<String, String>emptyMap());
OperationHandle opHandle1 = client.executeStatement(session1, "select 1 + 1", null);
Operation operation1 = sessionManager.getOperationManager().getOperation(opHandle1);
String logLocation = operation1.getOperationLog().toString();
// as the historic log is enabled, the log dir of the operation1 should be under the historic dir
assertTrue(logLocation.startsWith(OperationLogManager.getHistoricLogDir()));
File operationLogFile = new File(operation1.getOperationLog().toString());
assertTrue(operationLogFile.exists());
client.closeOperation(opHandle1);
// now close the session1
client.closeSession(session1);
// check that the log of operation1 is exist even if the session1 has been closed
assertTrue(operationLogFile.exists());
SessionHandle session2 = client.openSession("user1", "foobar", Collections.<String, String>emptyMap());
OperationHandle opHandle2 = client.executeStatement(session2, "select 1 + 1", null);
Operation operation2 = sessionManager.getOperationManager().getOperation(opHandle2);
// as the historic log is enabled, the log dir of the operation2 should be under the historic dir
logLocation = operation2.getOperationLog().toString();
assertTrue(logLocation.startsWith(OperationLogManager.getHistoricLogDir()));
// remove the query info of operation1 from the cache
client.closeOperation(opHandle2);
// the operation1 becomes unreachable
OperationManager operationManager = sessionManager.getOperationManager();
assertTrue(operationManager.getAllCachedQueryIds().size() == 1 && operationManager.getLiveQueryInfos().isEmpty());
assertNull(operationManager.getQueryInfo(opHandle1.getHandleIdentifier().toString()));
// now the session1 is closed and has no cached query info, the historic session log dir should be returned.
OperationLogManager logManager = sessionManager.getLogManager().get();
List<File> expiredLogDirs = logManager.getExpiredSessionLogDirs();
List<File> expiredOperationLogs = logManager.getExpiredOperationLogFiles();
assertEquals(operation1.getQueryId(), expiredOperationLogs.get(0).getName());
assertEquals(session1.getHandleIdentifier().toString(), expiredLogDirs.get(0).getName());
logManager.removeExpiredOperationLogAndDir();
// the historic session log dir has been cleanup
assertFalse(operationLogFile.exists());
assertFalse(expiredLogDirs.get(0).exists());
// though session2 is closed, but there exists his operation(operation2) in cache and
// log file under the historic session log dir, so the historic log dir of session2 would not be cleaned
client.closeSession(session2);
assertNotNull(operationManager.getQueryInfo(opHandle2.getHandleIdentifier().toString()));
assertTrue(operationManager.getAllCachedQueryIds().size() == 1 && operationManager.getLiveQueryInfos().isEmpty());
expiredOperationLogs = logManager.getExpiredOperationLogFiles();
expiredLogDirs = logManager.getExpiredSessionLogDirs();
assertTrue(expiredLogDirs.isEmpty());
assertTrue(expiredOperationLogs.isEmpty());
logManager.removeExpiredOperationLogAndDir();
assertTrue(new File(logLocation).getParentFile().exists());
FileUtils.deleteQuietly(new File(OperationLogManager.getHistoricLogDir()));
}
use of org.apache.hive.service.cli.OperationHandle in project hive by apache.
the class TestQueryShutdownHooks method testShutdownHookManagerIsRegistered.
@Test
public void testShutdownHookManagerIsRegistered() throws HiveSQLException, InterruptedException {
int shutdownHooksBeforeQuery = ShutdownHookManagerInspector.getShutdownHookCount();
String queryStr = "select reflect(\"java.lang.Thread\", \"sleep\", bigint(5000))";
OperationHandle opHandle = client.executeStatementAsync(sessionHandle, queryStr, confOverlay);
assertNotNull(opHandle);
ShutdownHookManagerInspector.assertShutdownHookCount(shutdownHooksBeforeQuery + 1);
final long step = 200;
final long timeout = System.currentTimeMillis() + ASYNC_QUERY_TIMEOUT_MS;
while (true) {
OperationStatus operationStatus = client.getOperationStatus(opHandle, false);
if (operationStatus.getState() == OperationState.FINISHED) {
break;
}
if (System.currentTimeMillis() > timeout) {
fail("Query did not complete timely");
}
Thread.sleep(step);
}
ShutdownHookManagerInspector.assertShutdownHookCount(shutdownHooksBeforeQuery);
}
use of org.apache.hive.service.cli.OperationHandle in project hive by apache.
the class TestQueryShutdownHooks method testSync.
@Test
public void testSync() throws Exception {
int shutdownHooksBeforeQueries = ShutdownHookManagerInspector.getShutdownHookCount();
String[] someQueries = { "CREATE TABLE sample_shutdown_hook (sample_id int, sample_value string)", "INSERT INTO sample_shutdown_hook VALUES (1, 'a')", "INSERT INTO sample_shutdown_hook VALUES (2, 'b')", "INSERT INTO sample_shutdown_hook VALUES (3, 'c')", "INSERT INTO sample_shutdown_hook VALUES (4, 'd')", "INSERT INTO sample_shutdown_hook VALUES (5, 'e')", "INSERT INTO sample_shutdown_hook VALUES (6, 'f')", "INSERT INTO sample_shutdown_hook VALUES (7, 'g')", "SELECT * FROM sample_shutdown_hook", "DROP TABLE sample_shutdown_hook" };
for (String queryStr : someQueries) {
OperationHandle opHandle = client.executeStatement(sessionHandle, queryStr, confOverlay);
assertNotNull(opHandle);
OperationStatus opStatus = client.getOperationStatus(opHandle, false);
assertNotNull(opStatus);
OperationState state = opStatus.getState();
assertEquals("Query should be finished", OperationState.FINISHED, state);
}
ShutdownHookManagerInspector.assertShutdownHookCount(shutdownHooksBeforeQueries);
}
Aggregations