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);
}
}
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;
}
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;
}
Aggregations