Search in sources :

Example 6 with OperationStatus

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

the class ThriftCLIServiceTest method testExecuteStatementAsync.

/**
   * Test asynchronous query execution and error reporting to the client
   * @throws Exception
   */
@Test
public void testExecuteStatementAsync() 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);
    OperationHandle opHandle;
    OperationStatus opStatus;
    OperationState state = null;
    // 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_ASYNC_THRIFT";
    client.executeStatement(sessHandle, queryString, opConf);
    // Create a test table
    queryString = "CREATE TABLE TEST_EXEC_ASYNC_THRIFT(ID STRING)";
    client.executeStatement(sessHandle, queryString, opConf);
    // Execute another query
    queryString = "SELECT ID+1 FROM TEST_EXEC_ASYNC_THRIFT";
    System.out.println("Will attempt to execute: " + queryString);
    opHandle = client.executeStatementAsync(sessHandle, queryString, opConf);
    assertNotNull(opHandle);
    // Poll on the operation status till the query is completed
    boolean isQueryRunning = true;
    long pollTimeout = System.currentTimeMillis() + 100000;
    while (isQueryRunning) {
        // Break if polling times out
        if (System.currentTimeMillis() > pollTimeout) {
            System.out.println("Polling timed out");
            break;
        }
        opStatus = client.getOperationStatus(opHandle, false);
        assertNotNull(opStatus);
        state = opStatus.getState();
        System.out.println("Current state: " + state);
        if (state == OperationState.CANCELED || state == OperationState.CLOSED || state == OperationState.FINISHED || state == OperationState.ERROR) {
            isQueryRunning = false;
        }
        Thread.sleep(1000);
    }
    // Expect query to be successfully completed now
    assertEquals("Query should be finished", OperationState.FINISHED, state);
    // Execute a malformed query
    // This query will give a runtime error
    queryString = "CREATE TABLE NON_EXISTING_TAB (ID STRING) location 'hdfs://localhost:10000/a/b/c'";
    System.out.println("Will attempt to execute: " + queryString);
    opHandle = client.executeStatementAsync(sessHandle, queryString, opConf);
    assertNotNull(opHandle);
    opStatus = client.getOperationStatus(opHandle, false);
    assertNotNull(opStatus);
    isQueryRunning = true;
    pollTimeout = System.currentTimeMillis() + 100000;
    while (isQueryRunning) {
        // Break if polling times out
        if (System.currentTimeMillis() > pollTimeout) {
            System.out.println("Polling timed out");
            break;
        }
        state = opStatus.getState();
        System.out.println("Current state: " + state);
        if (state == OperationState.CANCELED || state == OperationState.CLOSED || state == OperationState.FINISHED || state == OperationState.ERROR) {
            isQueryRunning = false;
        }
        Thread.sleep(1000);
        opStatus = client.getOperationStatus(opHandle, false);
    }
    // Expect query to return an error state
    assertEquals("Operation should be in error state", OperationState.ERROR, state);
    // sqlState, errorCode should be set to appropriate values
    assertEquals(opStatus.getOperationException().getSQLState(), "08S01");
    assertEquals(opStatus.getOperationException().getErrorCode(), 1);
    // Cleanup
    queryString = "DROP TABLE TEST_EXEC_ASYNC_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 7 with OperationStatus

use of org.apache.hive.service.cli.OperationStatus 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 8 with OperationStatus

use of org.apache.hive.service.cli.OperationStatus in project cdap by caskdata.

the class Hive12CDH5ExploreService method doFetchStatus.

@Override
protected QueryStatus doFetchStatus(OperationHandle handle) throws HiveSQLException, ExploreException, HandleNotFoundException {
    OperationStatus operationStatus = getCliService().getOperationStatus(handle);
    @SuppressWarnings("ThrowableResultOfMethodCallIgnored") HiveSQLException hiveExn = operationStatus.getOperationException();
    if (hiveExn != null) {
        return new QueryStatus(hiveExn.getMessage(), hiveExn.getSQLState());
    }
    return new QueryStatus(QueryStatus.OpStatus.valueOf(operationStatus.getState().toString()), handle.hasResultSet());
}
Also used : OperationStatus(org.apache.hive.service.cli.OperationStatus) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) QueryStatus(co.cask.cdap.proto.QueryStatus)

Example 9 with OperationStatus

use of org.apache.hive.service.cli.OperationStatus in project cdap by caskdata.

the class Hive13ExploreService method doFetchStatus.

@Override
protected QueryStatus doFetchStatus(OperationHandle operationHandle) throws HiveSQLException, ExploreException, HandleNotFoundException {
    OperationStatus operationStatus = getCliService().getOperationStatus(operationHandle);
    @SuppressWarnings("ThrowableResultOfMethodCallIgnored") HiveSQLException hiveExn = operationStatus.getOperationException();
    if (hiveExn != null) {
        return new QueryStatus(hiveExn.getMessage(), hiveExn.getSQLState());
    }
    return new QueryStatus(QueryStatus.OpStatus.valueOf(operationStatus.getState().toString()), operationHandle.hasResultSet());
}
Also used : OperationStatus(org.apache.hive.service.cli.OperationStatus) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) QueryStatus(co.cask.cdap.proto.QueryStatus)

Aggregations

OperationStatus (org.apache.hive.service.cli.OperationStatus)9 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)5 OperationHandle (org.apache.hive.service.cli.OperationHandle)5 OperationState (org.apache.hive.service.cli.OperationState)5 Test (org.junit.Test)4 QueryStatus (co.cask.cdap.proto.QueryStatus)3 HashMap (java.util.HashMap)3 SessionHandle (org.apache.hive.service.cli.SessionHandle)3 TGetOperationStatusResp (org.apache.hive.service.rpc.thrift.TGetOperationStatusResp)2 TException (org.apache.thrift.TException)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UnknownHostException (java.net.UnknownHostException)1 LoginException (javax.security.auth.login.LoginException)1 ServiceException (org.apache.hive.service.ServiceException)1 CLIService (org.apache.hive.service.cli.CLIService)1 JobProgressUpdate (org.apache.hive.service.cli.JobProgressUpdate)1 ProgressMonitorStatusMapper (org.apache.hive.service.cli.ProgressMonitorStatusMapper)1 RowSet (org.apache.hive.service.cli.RowSet)1 TezProgressMonitorStatusMapper (org.apache.hive.service.cli.TezProgressMonitorStatusMapper)1