Search in sources :

Example 6 with OperationState

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

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

the class OperationManager method cancelOperation.

/**
   * Cancel the running operation unless it is already in a terminal state
   * @param opHandle
   * @throws HiveSQLException
   */
public void cancelOperation(OperationHandle opHandle) throws HiveSQLException {
    Operation operation = getOperation(opHandle);
    OperationState opState = operation.getStatus().getState();
    if (opState.isTerminal()) {
        // Cancel should be a no-op in either cases
        LOG.debug(opHandle + ": Operation is already aborted in state - " + opState);
    } else {
        LOG.debug(opHandle + ": Attempting to cancel from state - " + opState);
        operation.cancel(OperationState.CANCELED);
        if (operation instanceof SQLOperation) {
            removeSaveSqlOperationDisplay(opHandle);
        }
    }
}
Also used : OperationState(org.apache.hive.service.cli.OperationState)

Example 8 with OperationState

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

the class Hive12ExploreService method doFetchStatus.

@Override
protected QueryStatus doFetchStatus(OperationHandle operationHandle) throws HiveSQLException, ExploreException, HandleNotFoundException {
    try {
        // In Hive 12, CLIService.getOperationStatus returns OperationState.
        // In Hive 13, CLIService.getOperationStatus returns OperationStatus.
        // Since we use Hive 13 for dev, we need the following workaround to get Hive 12 working.
        Class<? extends CLIService> cliServiceClass = getCliService().getClass();
        Method m = cliServiceClass.getMethod("getOperationStatus", OperationHandle.class);
        OperationState operationState = (OperationState) m.invoke(getCliService(), operationHandle);
        return new QueryStatus(QueryStatus.OpStatus.valueOf(operationState.toString()), operationHandle.hasResultSet());
    } catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
        throw Throwables.propagate(e);
    }
}
Also used : Method(java.lang.reflect.Method) QueryStatus(co.cask.cdap.proto.QueryStatus) OperationState(org.apache.hive.service.cli.OperationState) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 9 with OperationState

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

the class OperationManager method cancelOperation.

/**
 * Cancel the running operation unless it is already in a terminal state
 * @param opHandle operation handle
 * @param errMsg error message
 * @throws HiveSQLException
 */
public void cancelOperation(OperationHandle opHandle, String errMsg) throws HiveSQLException {
    Operation operation = getOperation(opHandle);
    OperationState opState = operation.getStatus().getState();
    if (opState.isTerminal()) {
        // Cancel should be a no-op in either cases
        LOG.debug(opHandle + ": Operation is already aborted in state - " + opState);
    } else {
        LOG.debug(opHandle + ": Attempting to cancel from state - " + opState);
        OperationState operationState = OperationState.CANCELED;
        operationState.setErrorMessage(errMsg);
        operation.cancel(operationState);
        if (operation instanceof SQLOperation) {
            removeSafeQueryInfo(opHandle);
        }
    }
}
Also used : OperationState(org.apache.hive.service.cli.OperationState)

Example 10 with OperationState

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

the class SQLOperation method getNextRowSet.

@Override
public RowSet getNextRowSet(FetchOrientation orientation, long maxRows) throws HiveSQLException {
    validateDefaultFetchOrientation(orientation);
    assertState(new ArrayList<OperationState>(Arrays.asList(OperationState.FINISHED)));
    FetchTask fetchTask = driver.getFetchTask();
    boolean isBlobBased = false;
    if (fetchTask != null && fetchTask.getWork().isUsingThriftJDBCBinarySerDe()) {
        // Just fetch one blob if we've serialized thrift objects in final tasks
        maxRows = 1;
        isBlobBased = true;
    }
    driver.setMaxRows((int) maxRows);
    RowSet rowSet = RowSetFactory.create(resultSchema, getProtocolVersion(), isBlobBased);
    try {
        /* if client is requesting fetch-from-start and its not the first time reading from this operation
       * then reset the fetch position to beginning
       */
        if (orientation.equals(FetchOrientation.FETCH_FIRST) && fetchStarted) {
            driver.resetFetch();
        }
        fetchStarted = true;
        driver.setMaxRows((int) maxRows);
        if (driver.getResults(convey)) {
            return decode(convey, rowSet);
        }
        return rowSet;
    } catch (IOException e) {
        throw new HiveSQLException(e);
    } catch (Exception e) {
        throw new HiveSQLException(e);
    } finally {
        convey.clear();
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) RowSet(org.apache.hive.service.cli.RowSet) IOException(java.io.IOException) OperationState(org.apache.hive.service.cli.OperationState) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SQLException(java.sql.SQLException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) IOException(java.io.IOException) SerDeException(org.apache.hadoop.hive.serde2.SerDeException) FetchTask(org.apache.hadoop.hive.ql.exec.FetchTask)

Aggregations

OperationState (org.apache.hive.service.cli.OperationState)11 OperationStatus (org.apache.hive.service.cli.OperationStatus)5 OperationHandle (org.apache.hive.service.cli.OperationHandle)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)3 SessionHandle (org.apache.hive.service.cli.SessionHandle)3 RowSet (org.apache.hive.service.cli.RowSet)2 QueryStatus (co.cask.cdap.proto.QueryStatus)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 SQLException (java.sql.SQLException)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 FetchTask (org.apache.hadoop.hive.ql.exec.FetchTask)1 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)1 TGetOperationStatusReq (org.apache.hive.service.rpc.thrift.TGetOperationStatusReq)1 TGetOperationStatusResp (org.apache.hive.service.rpc.thrift.TGetOperationStatusResp)1 TException (org.apache.thrift.TException)1