Search in sources :

Example 1 with OperationStatus

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

the class ThriftCLIServiceTest 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 2 with OperationStatus

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

use of org.apache.hive.service.cli.OperationStatus 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());
        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());
            resp.setErrorMessage(org.apache.hadoop.util.StringUtils.stringifyException(opException));
        } 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 OperationStatus

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

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

the class Hive14ExploreService method doFetchStatus.

@Override
protected QueryStatus doFetchStatus(OperationHandle operationHandle) throws HiveSQLException, ExploreException, HandleNotFoundException {
    OperationStatus operationStatus;
    CLIService cliService = getCliService();
    // Call the getOperationStatus method based on the number of arguments it expects.
    try {
        if (getOperationStatus.getParameterTypes().length == 2) {
            operationStatus = (OperationStatus) getOperationStatus.invoke(cliService, operationHandle, true);
        } else {
            operationStatus = (OperationStatus) getOperationStatus.invoke(cliService, operationHandle);
        }
    } catch (IndexOutOfBoundsException | IllegalAccessException | InvocationTargetException e) {
        throw new RuntimeException("Failed to get the status of the operation.", e);
    }
    @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) CLIService(org.apache.hive.service.cli.CLIService) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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