use of co.cask.cdap.proto.QueryStatus in project cdap by caskdata.
the class Hive12CDH5ExploreService method doFetchStatus.
@Override
protected QueryStatus doFetchStatus(OperationHandle handle) throws HiveSQLException, ExploreException, HandleNotFoundException {
OperationStatus operationStatus = getCliService().getOperationStatus(handle);
@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()), handle.hasResultSet());
}
use of co.cask.cdap.proto.QueryStatus in project cdap by caskdata.
the class Hive13ExploreService method doFetchStatus.
@Override
protected QueryStatus doFetchStatus(OperationHandle operationHandle) throws HiveSQLException, ExploreException, HandleNotFoundException {
OperationStatus operationStatus = getCliService().getOperationStatus(operationHandle);
@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());
}
use of co.cask.cdap.proto.QueryStatus in project cdap by caskdata.
the class AbstractExploreClient method getFutureResultsFromHandle.
/**
* Create a {@link ListenableFuture} object by polling the Explore service using the
* {@link ListenableFuture} containing a {@link QueryHandle}.
*/
private ListenableFuture<ExploreExecutionResult> getFutureResultsFromHandle(final ListenableFuture<QueryHandle> futureHandle) {
final StatementExecutionFuture resultFuture = new StatementExecutionFuture(this, futureHandle);
Futures.addCallback(futureHandle, new FutureCallback<QueryHandle>() {
@Override
public void onSuccess(final QueryHandle handle) {
boolean mustCloseHandle;
try {
QueryStatus status = getStatus(handle);
if (!status.getStatus().isDone()) {
final String userId = SecurityRequestContext.getUserId();
final String userIp = SecurityRequestContext.getUserIP();
executor.schedule(new Runnable() {
@Override
public void run() {
SecurityRequestContext.setUserId(userId);
SecurityRequestContext.setUserIP(userIp);
onSuccess(handle);
}
}, 300, TimeUnit.MILLISECONDS);
return;
}
if (QueryStatus.OpStatus.ERROR.equals(status.getStatus())) {
throw new SQLException(status.getErrorMessage(), status.getSqlState());
}
ExploreExecutionResult result = new ClientExploreExecutionResult(AbstractExploreClient.this, handle, status);
mustCloseHandle = !resultFuture.set(result) || !status.hasResults();
} catch (Exception e) {
mustCloseHandle = true;
resultFuture.setException(e);
}
if (mustCloseHandle) {
try {
close(handle);
} catch (Throwable t) {
LOG.warn("Failed to close handle {}", handle, t);
}
}
}
@Override
public void onFailure(Throwable t) {
resultFuture.setException(t);
}
}, executor);
return resultFuture;
}
Aggregations