Search in sources :

Example 66 with OperationHandle

use of org.apache.hive.service.cli.OperationHandle in project hive by apache.

the class TestHiveServer2SessionTimeout method testConnection.

@Test
public void testConnection() throws Exception {
    CLIServiceClient serviceClient = miniHS2.getServiceClient();
    SessionHandle sessHandle = serviceClient.openSession("foo", "bar");
    OperationHandle handle = serviceClient.executeStatement(sessHandle, "SELECT 1", confOverlay);
    Thread.sleep(7000);
    try {
        serviceClient.closeOperation(handle);
        fail("Operation should have been closed by timeout!");
    } catch (HiveSQLException e) {
        assertTrue(StringUtils.stringifyException(e), e.getMessage().contains("Invalid OperationHandle"));
    }
}
Also used : CLIServiceClient(org.apache.hive.service.cli.CLIServiceClient) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Example 67 with OperationHandle

use of org.apache.hive.service.cli.OperationHandle in project hive by apache.

the class TestHiveShell method executeStatement.

public List<Object[]> executeStatement(String statement) {
    Preconditions.checkState(session != null, "You have to start TestHiveShell and open a session first, before running a query.");
    try {
        OperationHandle handle = client.executeStatement(session.getSessionHandle(), statement, Collections.emptyMap());
        List<Object[]> resultSet = new ArrayList<>();
        if (handle.hasResultSet()) {
            RowSet rowSet;
            // keep fetching results until we can
            while ((rowSet = client.fetchResults(handle)) != null && rowSet.numRows() > 0) {
                for (Object[] row : rowSet) {
                    resultSet.add(row.clone());
                }
            }
        }
        return resultSet;
    } catch (HiveSQLException e) {
        throw new IllegalArgumentException("Failed to execute Hive query '" + statement + "': " + e.getMessage(), e);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) ArrayList(java.util.ArrayList) RowSet(org.apache.hive.service.cli.RowSet) OperationHandle(org.apache.hive.service.cli.OperationHandle)

Example 68 with OperationHandle

use of org.apache.hive.service.cli.OperationHandle in project hive by apache.

the class TestOperationLoggingLayout method testHushableRandomAccessFileAppender.

@Test
public /**
 * Test to make sure that appending log event to HushableRandomAccessFileAppender even after
 * closing the corresponding operation would not throw an exception.
 */
void testHushableRandomAccessFileAppender() throws Exception {
    // verify whether the sql operation log is generated and fetch correctly.
    OperationHandle operationHandle = client.executeStatement(sessionHandle, sqlCntStar, null);
    RowSet rowSetLog = client.fetchResults(operationHandle, FetchOrientation.FETCH_FIRST, 1000, FetchType.LOG);
    Appender queryAppender;
    Appender testQueryAppender;
    String queryId = getQueryId(rowSetLog);
    Assert.assertNotNull("Could not find query id, perhaps a logging message changed", queryId);
    checkAppenderState("before operation close ", LogDivertAppender.QUERY_ROUTING_APPENDER, queryId, false);
    queryAppender = getAppender(LogDivertAppender.QUERY_ROUTING_APPENDER, queryId);
    checkAppenderState("before operation close ", LogDivertAppenderForTest.TEST_QUERY_ROUTING_APPENDER, queryId, false);
    testQueryAppender = getAppender(LogDivertAppenderForTest.TEST_QUERY_ROUTING_APPENDER, queryId);
    client.closeOperation(operationHandle);
    appendHushableRandomAccessFileAppender(queryAppender);
    appendHushableRandomAccessFileAppender(testQueryAppender);
}
Also used : Appender(org.apache.logging.log4j.core.Appender) LogDivertAppender(org.apache.hadoop.hive.ql.log.LogDivertAppender) RoutingAppender(org.apache.logging.log4j.core.appender.routing.RoutingAppender) HushableRandomAccessFileAppender(org.apache.hadoop.hive.ql.log.HushableRandomAccessFileAppender) RowSet(org.apache.hive.service.cli.RowSet) OperationHandle(org.apache.hive.service.cli.OperationHandle) LogDivertAppenderForTest(org.apache.hadoop.hive.ql.log.LogDivertAppenderForTest) Test(org.junit.Test)

Example 69 with OperationHandle

use of org.apache.hive.service.cli.OperationHandle in project hive by apache.

the class TestOperationLoggingAPIWithMr method testFetchResultsOfLogAsync.

@Test
public void testFetchResultsOfLogAsync() throws Exception {
    // verify whether the sql operation log is generated and fetch correctly in async mode.
    OperationHandle operationHandle = client.executeStatementAsync(sessionHandle, sql, null);
    // Poll on the operation status till the query is completed
    boolean isQueryRunning = true;
    long pollTimeout = System.currentTimeMillis() + 100000;
    OperationStatus opStatus;
    OperationState state = null;
    RowSet rowSetAccumulated = null;
    StringBuilder logs = new StringBuilder();
    while (isQueryRunning) {
        // Break if polling times out
        if (System.currentTimeMillis() > pollTimeout) {
            break;
        }
        opStatus = client.getOperationStatus(operationHandle, false);
        Assert.assertNotNull(opStatus);
        state = opStatus.getState();
        rowSetAccumulated = client.fetchResults(operationHandle, FetchOrientation.FETCH_NEXT, 2000, FetchType.LOG);
        for (Object[] row : rowSetAccumulated) {
            logs.append(row[0]);
        }
        if (state == OperationState.CANCELED || state == OperationState.CLOSED || state == OperationState.FINISHED || state == OperationState.ERROR) {
            isQueryRunning = false;
        }
        Thread.sleep(10);
    }
    // The sql should be completed now.
    Assert.assertEquals("Query should be finished", OperationState.FINISHED, state);
    // Verify the accumulated logs
    verifyFetchedLogPost(logs.toString(), expectedLogsVerbose, true);
    // Verify the fetched logs from the beginning of the log file
    RowSet rowSet = client.fetchResults(operationHandle, FetchOrientation.FETCH_FIRST, 2000, FetchType.LOG);
    verifyFetchedLog(rowSet, expectedLogsVerbose);
}
Also used : OperationStatus(org.apache.hive.service.cli.OperationStatus) RowSet(org.apache.hive.service.cli.RowSet) OperationHandle(org.apache.hive.service.cli.OperationHandle) OperationState(org.apache.hive.service.cli.OperationState) Test(org.junit.Test)

Example 70 with OperationHandle

use of org.apache.hive.service.cli.OperationHandle in project hive by apache.

the class TestOperationLoggingAPIWithMr method testFetchResultsOfLog.

@Test
public void testFetchResultsOfLog() throws Exception {
    // verify whether the sql operation log is generated and fetch correctly.
    OperationHandle operationHandle = client.executeStatement(sessionHandle, sql, null);
    RowSet rowSetLog = client.fetchResults(operationHandle, FetchOrientation.FETCH_FIRST, 1000, FetchType.LOG);
    verifyFetchedLog(rowSetLog, expectedLogsVerbose);
}
Also used : RowSet(org.apache.hive.service.cli.RowSet) OperationHandle(org.apache.hive.service.cli.OperationHandle) 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