Search in sources :

Example 91 with OperationHandle

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);
    }
}
Also used : TGetTypeInfoReq(org.apache.hive.service.rpc.thrift.TGetTypeInfoReq) TGetTypeInfoResp(org.apache.hive.service.rpc.thrift.TGetTypeInfoResp) TProtocolVersion(org.apache.hive.service.rpc.thrift.TProtocolVersion) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TOperationHandle(org.apache.hive.service.rpc.thrift.TOperationHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TException(org.apache.thrift.TException)

Example 92 with OperationHandle

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());
}
Also used : HashMap(java.util.HashMap) SessionHandle(org.apache.hive.service.cli.SessionHandle) JsonNode(com.fasterxml.jackson.databind.JsonNode) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Example 93 with OperationHandle

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()));
}
Also used : SessionManager(org.apache.hive.service.cli.session.SessionManager) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) File(java.io.File) CLIService(org.apache.hive.service.cli.CLIService) EmbeddedThriftBinaryCLIService(org.apache.hive.service.cli.thrift.EmbeddedThriftBinaryCLIService) ThriftCLIServiceClient(org.apache.hive.service.cli.thrift.ThriftCLIServiceClient) Test(org.junit.Test)

Example 94 with OperationHandle

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);
}
Also used : OperationStatus(org.apache.hive.service.cli.OperationStatus) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Example 95 with OperationHandle

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);
}
Also used : OperationStatus(org.apache.hive.service.cli.OperationStatus) OperationHandle(org.apache.hive.service.cli.OperationHandle) OperationState(org.apache.hive.service.cli.OperationState) Test(org.junit.Test)

Aggregations

OperationHandle (org.apache.hive.service.cli.OperationHandle)104 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)63 SessionHandle (org.apache.hive.service.cli.SessionHandle)47 Test (org.junit.Test)35 TException (org.apache.thrift.TException)31 RowSet (org.apache.hive.service.cli.RowSet)21 IOException (java.io.IOException)20 UnknownHostException (java.net.UnknownHostException)17 LoginException (javax.security.auth.login.LoginException)17 ServiceException (org.apache.hive.service.ServiceException)17 OperationManager (org.apache.hive.service.cli.operation.OperationManager)14 TProtocolVersion (org.apache.hive.service.rpc.thrift.TProtocolVersion)13 ExploreException (co.cask.cdap.explore.service.ExploreException)12 TOperationHandle (org.apache.hive.service.rpc.thrift.TOperationHandle)12 QueryHandle (co.cask.cdap.proto.QueryHandle)11 OperationStatus (org.apache.hive.service.cli.OperationStatus)8 HashMap (java.util.HashMap)7 CLIServiceClient (org.apache.hive.service.cli.CLIServiceClient)6 ArrayList (java.util.ArrayList)5 OperationState (org.apache.hive.service.cli.OperationState)5