Search in sources :

Example 41 with OperationHandle

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

the class ThriftCliServiceTestWithCookie method testExecuteStatement.

/**
 * Test synchronous query execution
 * @throws Exception
 */
@Test
public void testExecuteStatement() throws Exception {
    Map<String, String> opConf = new HashMap<String, String>();
    // Open a new client session
    SessionHandle sessHandle = client.openSession(USERNAME, PASSWORD, opConf);
    // Session handle should not be null
    assertNotNull("Session handle should not be null", sessHandle);
    // Change lock manager to embedded mode
    String queryString = "SET hive.lock.manager=" + "org.apache.hadoop.hive.ql.lockmgr.EmbeddedLockManager";
    client.executeStatement(sessHandle, queryString, opConf);
    // Drop the table if it exists
    queryString = "DROP TABLE IF EXISTS TEST_EXEC_THRIFT";
    client.executeStatement(sessHandle, queryString, opConf);
    // Create a test table
    queryString = "CREATE TABLE TEST_EXEC_THRIFT(ID STRING)";
    client.executeStatement(sessHandle, queryString, opConf);
    // Execute another query
    queryString = "SELECT ID+1 FROM TEST_EXEC_THRIFT";
    OperationHandle opHandle = client.executeStatement(sessHandle, queryString, opConf);
    assertNotNull(opHandle);
    OperationStatus opStatus = client.getOperationStatus(opHandle, false);
    assertNotNull(opStatus);
    OperationState state = opStatus.getState();
    // Expect query to be completed now
    assertEquals("Query should be finished", OperationState.FINISHED, state);
    // Cleanup
    queryString = "DROP TABLE TEST_EXEC_THRIFT";
    client.executeStatement(sessHandle, queryString, opConf);
    client.closeSession(sessHandle);
}
Also used : HashMap(java.util.HashMap) OperationStatus(org.apache.hive.service.cli.OperationStatus) SessionHandle(org.apache.hive.service.cli.SessionHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) OperationState(org.apache.hive.service.cli.OperationState) Test(org.junit.Test)

Example 42 with OperationHandle

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

the class OperationLoggingAPITestBase method testFetchResultsOfLogWithVerboseMode.

@Test
public void testFetchResultsOfLogWithVerboseMode() throws Exception {
    String queryString = "set hive.server2.logging.operation.level=verbose";
    client.executeStatement(sessionHandle, queryString, null);
    // 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);
    // Verbose Logs should contain everything, including execution and performance
    verifyFetchedLog(rowSetLog, expectedLogsVerbose);
    verifyFetchedLog(rowSetLog, expectedLogsExecution);
    verifyFetchedLog(rowSetLog, expectedLogsPerformance);
}
Also used : RowSet(org.apache.hive.service.cli.RowSet) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Example 43 with OperationHandle

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

the class OperationLoggingAPITestBase method testFetchResultsOfLogWithNoneMode.

@Test
public void testFetchResultsOfLogWithNoneMode() throws Exception {
    try {
        String queryString = "set hive.server2.logging.operation.level=none";
        client.executeStatement(sessionHandle, queryString, null);
        // 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);
        // We should not get any rows.
        assert (rowSetLog.numRows() == 0);
    } finally {
        // Restore everything to default setup to avoid discrepancy between junit test runs
        String queryString2 = "set hive.server2.logging.operation.level=verbose";
        client.executeStatement(sessionHandle, queryString2, null);
    }
}
Also used : RowSet(org.apache.hive.service.cli.RowSet) OperationHandle(org.apache.hive.service.cli.OperationHandle) Test(org.junit.Test)

Example 44 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)

Example 45 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)

Aggregations

OperationHandle (org.apache.hive.service.cli.OperationHandle)79 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)55 SessionHandle (org.apache.hive.service.cli.SessionHandle)38 TException (org.apache.thrift.TException)27 Test (org.junit.Test)23 IOException (java.io.IOException)18 RowSet (org.apache.hive.service.cli.RowSet)17 UnknownHostException (java.net.UnknownHostException)15 LoginException (javax.security.auth.login.LoginException)15 ServiceException (org.apache.hive.service.ServiceException)15 ExploreException (co.cask.cdap.explore.service.ExploreException)12 OperationManager (org.apache.hive.service.cli.operation.OperationManager)12 QueryHandle (co.cask.cdap.proto.QueryHandle)11 TProtocolVersion (org.apache.hive.service.rpc.thrift.TProtocolVersion)11 TOperationHandle (org.apache.hive.service.rpc.thrift.TOperationHandle)10 OperationStatus (org.apache.hive.service.cli.OperationStatus)5 HashMap (java.util.HashMap)4 CLIServiceClient (org.apache.hive.service.cli.CLIServiceClient)4 OperationState (org.apache.hive.service.cli.OperationState)4 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)2