Search in sources :

Example 1 with TGetOperationStatusReq

use of org.apache.hive.service.rpc.thrift.TGetOperationStatusReq in project hive by apache.

the class ThriftCLIServiceClient method getOperationStatus.

/* (non-Javadoc)
   * @see org.apache.hive.service.cli.ICLIService#getOperationStatus(org.apache.hive.service.cli.OperationHandle)
   */
@Override
public OperationStatus getOperationStatus(OperationHandle opHandle, boolean getProgressUpdate) throws HiveSQLException {
    try {
        TGetOperationStatusReq req = new TGetOperationStatusReq(opHandle.toTOperationHandle());
        req.setGetProgressUpdate(getProgressUpdate);
        TGetOperationStatusResp resp = cliService.GetOperationStatus(req);
        // Checks the status of the RPC call, throws an exception in case of error
        checkStatus(resp.getStatus());
        OperationState opState = OperationState.getOperationState(resp.getOperationState());
        HiveSQLException opException = null;
        if (opState == OperationState.ERROR) {
            opException = new HiveSQLException(resp.getErrorMessage(), resp.getSqlState(), resp.getErrorCode());
        }
        return new OperationStatus(opState, resp.getTaskStatus(), resp.getOperationStarted(), resp.getOperationCompleted(), resp.isHasResultSet(), opException);
    } catch (HiveSQLException e) {
        throw e;
    } catch (Exception e) {
        throw new HiveSQLException(e);
    }
}
Also used : TGetOperationStatusResp(org.apache.hive.service.rpc.thrift.TGetOperationStatusResp) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) OperationStatus(org.apache.hive.service.cli.OperationStatus) TGetOperationStatusReq(org.apache.hive.service.rpc.thrift.TGetOperationStatusReq) OperationState(org.apache.hive.service.cli.OperationState) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TException(org.apache.thrift.TException)

Example 2 with TGetOperationStatusReq

use of org.apache.hive.service.rpc.thrift.TGetOperationStatusReq in project hive by apache.

the class HiveStatement method waitForOperationToComplete.

TGetOperationStatusResp waitForOperationToComplete() throws SQLException {
    TGetOperationStatusReq statusReq = new TGetOperationStatusReq(stmtHandle);
    boolean shouldGetProgressUpdate = inPlaceUpdateStream != InPlaceUpdateStream.NO_OP;
    statusReq.setGetProgressUpdate(shouldGetProgressUpdate);
    if (!shouldGetProgressUpdate) {
        /**
         * progress bar is completed if there is nothing we want to request in the first place.
         */
        inPlaceUpdateStream.getEventNotifier().progressBarCompleted();
    }
    TGetOperationStatusResp statusResp = null;
    // Poll on the operation status, till the operation is complete
    while (!isOperationComplete) {
        try {
            /**
             * For an async SQLOperation, GetOperationStatus will use the long polling approach It will
             * essentially return after the HIVE_SERVER2_LONG_POLLING_TIMEOUT (a server config) expires
             */
            statusResp = client.GetOperationStatus(statusReq);
            inPlaceUpdateStream.update(statusResp.getProgressUpdateResponse());
            Utils.verifySuccessWithInfo(statusResp.getStatus());
            if (statusResp.isSetOperationState()) {
                switch(statusResp.getOperationState()) {
                    case CLOSED_STATE:
                    case FINISHED_STATE:
                        isOperationComplete = true;
                        isLogBeingGenerated = false;
                        break;
                    case CANCELED_STATE:
                        // 01000 -> warning
                        String errMsg = statusResp.getErrorMessage();
                        if (errMsg != null && !errMsg.isEmpty()) {
                            throw new SQLException("Query was cancelled. " + errMsg, "01000");
                        } else {
                            throw new SQLException("Query was cancelled", "01000");
                        }
                    case TIMEDOUT_STATE:
                        throw new SQLTimeoutException("Query timed out after " + queryTimeout + " seconds");
                    case ERROR_STATE:
                        // Get the error details from the underlying exception
                        throw new SQLException(statusResp.getErrorMessage(), statusResp.getSqlState(), statusResp.getErrorCode());
                    case UKNOWN_STATE:
                        throw new SQLException("Unknown query", "HY000");
                    case INITIALIZED_STATE:
                    case PENDING_STATE:
                    case RUNNING_STATE:
                        break;
                }
            }
        } catch (SQLException e) {
            isLogBeingGenerated = false;
            throw e;
        } catch (Exception e) {
            isLogBeingGenerated = false;
            throw new SQLException(e.toString(), "08S01", e);
        }
    }
    /*
      we set progress bar to be completed when hive query execution has completed
    */
    inPlaceUpdateStream.getEventNotifier().progressBarCompleted();
    return statusResp;
}
Also used : SQLException(java.sql.SQLException) TGetOperationStatusResp(org.apache.hive.service.rpc.thrift.TGetOperationStatusResp) SQLTimeoutException(java.sql.SQLTimeoutException) TGetOperationStatusReq(org.apache.hive.service.rpc.thrift.TGetOperationStatusReq) SQLFeatureNotSupportedException(java.sql.SQLFeatureNotSupportedException) SQLTimeoutException(java.sql.SQLTimeoutException) SQLException(java.sql.SQLException) TException(org.apache.thrift.TException)

Example 3 with TGetOperationStatusReq

use of org.apache.hive.service.rpc.thrift.TGetOperationStatusReq in project hive by apache.

the class HiveStatement method waitForResultSetStatus.

/**
 * Poll the result set status by checking if isSetHasResultSet is set
 * @return
 * @throws SQLException
 */
private TGetOperationStatusResp waitForResultSetStatus() throws SQLException {
    TGetOperationStatusReq statusReq = new TGetOperationStatusReq(stmtHandle);
    TGetOperationStatusResp statusResp = null;
    while (statusResp == null || !statusResp.isSetHasResultSet()) {
        try {
            statusResp = client.GetOperationStatus(statusReq);
        } catch (TException e) {
            isLogBeingGenerated = false;
            throw new SQLException(e.toString(), "08S01", e);
        }
    }
    return statusResp;
}
Also used : TException(org.apache.thrift.TException) SQLException(java.sql.SQLException) TGetOperationStatusResp(org.apache.hive.service.rpc.thrift.TGetOperationStatusResp) TGetOperationStatusReq(org.apache.hive.service.rpc.thrift.TGetOperationStatusReq)

Aggregations

TGetOperationStatusReq (org.apache.hive.service.rpc.thrift.TGetOperationStatusReq)3 TGetOperationStatusResp (org.apache.hive.service.rpc.thrift.TGetOperationStatusResp)3 TException (org.apache.thrift.TException)3 SQLException (java.sql.SQLException)2 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 SQLTimeoutException (java.sql.SQLTimeoutException)1 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)1 OperationState (org.apache.hive.service.cli.OperationState)1 OperationStatus (org.apache.hive.service.cli.OperationStatus)1