use of io.cdap.cdap.proto.QueryStatus in project cdap by cdapio.
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 io.cdap.cdap.proto.QueryStatus in project cdap by cdapio.
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 io.cdap.cdap.proto.QueryStatus in project cdap by cdapio.
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());
}
use of io.cdap.cdap.proto.QueryStatus in project cdap by cdapio.
the class ExploreQueryExecutorHttpHandler method getQueryStatus.
@GET
@Path("data/explore/queries/{id}/status")
public void getQueryStatus(HttpRequest request, HttpResponder responder, @PathParam("id") String id) throws ExploreException {
try {
final QueryHandle handle = QueryHandle.fromId(id);
QueryStatus status;
if (!handle.equals(QueryHandle.NO_OP)) {
status = doAs(handle, new Callable<QueryStatus>() {
@Override
public QueryStatus call() throws Exception {
return exploreService.getStatus(handle);
}
});
} else {
status = QueryStatus.NO_OP;
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(status));
} catch (IllegalArgumentException e) {
LOG.debug("Got exception:", e);
responder.sendString(HttpResponseStatus.BAD_REQUEST, e.getMessage());
} catch (SQLException e) {
LOG.debug("Got exception:", e);
responder.sendString(HttpResponseStatus.BAD_REQUEST, String.format("[SQLState %s] %s", e.getSQLState(), e.getMessage()));
} catch (HandleNotFoundException e) {
responder.sendStatus(HttpResponseStatus.NOT_FOUND);
} catch (ExploreException | RuntimeException e) {
LOG.debug("Got exception:", e);
throw e;
}
}
use of io.cdap.cdap.proto.QueryStatus in project cdap by cdapio.
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