Search in sources :

Example 1 with TGetOperationStatusResp

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

the class HiveStatement method executeAsync.

/**
 * Starts the query execution asynchronously on the server, and immediately returns to the client.
 * The client subsequently blocks on ResultSet#next or Statement#getUpdateCount, depending on the
 * query type. Users should call ResultSet.next or Statement#getUpdateCount (depending on whether
 * query returns results) to ensure that query completes successfully. Calling another execute*
 * method, or close before query completion would result in the async query getting killed if it
 * is not already finished.
 * Note: This method is an API for limited usage outside of Hive by applications like Apache Ambari,
 * although it is not part of the interface java.sql.Statement.
 *
 * @param sql
 * @return true if the first result is a ResultSet object; false if it is an update count or there
 *         are no results
 * @throws SQLException
 */
public boolean executeAsync(String sql) throws SQLException {
    runAsyncOnServer(sql);
    TGetOperationStatusResp status = waitForResultSetStatus();
    if (!status.isHasResultSet()) {
        return false;
    }
    resultSet = new HiveQueryResultSet.Builder(this).setClient(client).setSessionHandle(sessHandle).setStmtHandle(stmtHandle).setMaxRows(maxRows).setFetchSize(fetchSize).setScrollable(isScrollableResultset).build();
    return true;
}
Also used : TGetOperationStatusResp(org.apache.hive.service.rpc.thrift.TGetOperationStatusResp)

Example 2 with TGetOperationStatusResp

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

the class HiveStatement method execute.

/*
   * (non-Javadoc)
   *
   * @see java.sql.Statement#execute(java.lang.String)
   */
@Override
public boolean execute(String sql) throws SQLException {
    runAsyncOnServer(sql);
    TGetOperationStatusResp status = waitForOperationToComplete();
    // The query should be completed by now
    if (!status.isHasResultSet() && !stmtHandle.isHasResultSet()) {
        return false;
    }
    resultSet = new HiveQueryResultSet.Builder(this).setClient(client).setSessionHandle(sessHandle).setStmtHandle(stmtHandle).setMaxRows(maxRows).setFetchSize(fetchSize).setScrollable(isScrollableResultset).build();
    return true;
}
Also used : TGetOperationStatusResp(org.apache.hive.service.rpc.thrift.TGetOperationStatusResp)

Example 3 with TGetOperationStatusResp

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

the class ThriftCLIService method GetOperationStatus.

@Override
public TGetOperationStatusResp GetOperationStatus(TGetOperationStatusReq req) throws TException {
    TGetOperationStatusResp resp = new TGetOperationStatusResp();
    OperationHandle operationHandle = new OperationHandle(req.getOperationHandle());
    try {
        OperationStatus operationStatus = cliService.getOperationStatus(operationHandle, req.isGetProgressUpdate());
        resp.setOperationState(operationStatus.getState().toTOperationState());
        resp.setErrorMessage(operationStatus.getState().getErrorMessage());
        HiveSQLException opException = operationStatus.getOperationException();
        resp.setTaskStatus(operationStatus.getTaskStatus());
        resp.setOperationStarted(operationStatus.getOperationStarted());
        resp.setOperationCompleted(operationStatus.getOperationCompleted());
        resp.setHasResultSet(operationStatus.getHasResultSet());
        JobProgressUpdate progressUpdate = operationStatus.jobProgressUpdate();
        ProgressMonitorStatusMapper mapper = ProgressMonitorStatusMapper.DEFAULT;
        if ("tez".equals(hiveConf.getVar(ConfVars.HIVE_EXECUTION_ENGINE))) {
            mapper = new TezProgressMonitorStatusMapper();
        }
        TJobExecutionStatus executionStatus = mapper.forStatus(progressUpdate.status);
        resp.setProgressUpdateResponse(new TProgressUpdateResp(progressUpdate.headers(), progressUpdate.rows(), progressUpdate.progressedPercentage, executionStatus, progressUpdate.footerSummary, progressUpdate.startTimeMillis));
        if (opException != null) {
            resp.setSqlState(opException.getSQLState());
            resp.setErrorCode(opException.getErrorCode());
            if (opException.getErrorCode() == 29999)
                resp.setErrorMessage(org.apache.hadoop.util.StringUtils.stringifyException(opException));
            else
                resp.setErrorMessage(opException.getMessage());
        } else if (executionStatus == TJobExecutionStatus.NOT_AVAILABLE && OperationType.EXECUTE_STATEMENT.equals(operationHandle.getOperationType())) {
            resp.getProgressUpdateResponse().setProgressedPercentage(getProgressedPercentage(operationHandle));
        }
        resp.setStatus(OK_STATUS);
    } catch (Exception e) {
        LOG.warn("Error getting operation status: ", e);
        resp.setStatus(HiveSQLException.toTStatus(e));
    }
    return resp;
}
Also used : TJobExecutionStatus(org.apache.hive.service.rpc.thrift.TJobExecutionStatus) JobProgressUpdate(org.apache.hive.service.cli.JobProgressUpdate) TezProgressMonitorStatusMapper(org.apache.hive.service.cli.TezProgressMonitorStatusMapper) TGetOperationStatusResp(org.apache.hive.service.rpc.thrift.TGetOperationStatusResp) OperationStatus(org.apache.hive.service.cli.OperationStatus) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TezProgressMonitorStatusMapper(org.apache.hive.service.cli.TezProgressMonitorStatusMapper) ProgressMonitorStatusMapper(org.apache.hive.service.cli.ProgressMonitorStatusMapper) TProgressUpdateResp(org.apache.hive.service.rpc.thrift.TProgressUpdateResp) OperationHandle(org.apache.hive.service.cli.OperationHandle) LoginException(javax.security.auth.login.LoginException) ServiceException(org.apache.hive.service.ServiceException) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TException(org.apache.thrift.TException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 4 with TGetOperationStatusResp

use of org.apache.hive.service.rpc.thrift.TGetOperationStatusResp 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 5 with TGetOperationStatusResp

use of org.apache.hive.service.rpc.thrift.TGetOperationStatusResp 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)

Aggregations

TGetOperationStatusResp (org.apache.hive.service.rpc.thrift.TGetOperationStatusResp)6 TException (org.apache.thrift.TException)4 TGetOperationStatusReq (org.apache.hive.service.rpc.thrift.TGetOperationStatusReq)3 SQLException (java.sql.SQLException)2 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)2 OperationStatus (org.apache.hive.service.cli.OperationStatus)2 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 SQLTimeoutException (java.sql.SQLTimeoutException)1 LoginException (javax.security.auth.login.LoginException)1 ServiceException (org.apache.hive.service.ServiceException)1 JobProgressUpdate (org.apache.hive.service.cli.JobProgressUpdate)1 OperationHandle (org.apache.hive.service.cli.OperationHandle)1 OperationState (org.apache.hive.service.cli.OperationState)1 ProgressMonitorStatusMapper (org.apache.hive.service.cli.ProgressMonitorStatusMapper)1 TezProgressMonitorStatusMapper (org.apache.hive.service.cli.TezProgressMonitorStatusMapper)1 TJobExecutionStatus (org.apache.hive.service.rpc.thrift.TJobExecutionStatus)1 TProgressUpdateResp (org.apache.hive.service.rpc.thrift.TProgressUpdateResp)1