Search in sources :

Example 16 with QueryStatus

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());
}
Also used : OperationStatus(org.apache.hive.service.cli.OperationStatus) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) QueryStatus(io.cdap.cdap.proto.QueryStatus)

Example 17 with QueryStatus

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());
}
Also used : OperationStatus(org.apache.hive.service.cli.OperationStatus) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) QueryStatus(io.cdap.cdap.proto.QueryStatus)

Example 18 with QueryStatus

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());
}
Also used : OperationStatus(org.apache.hive.service.cli.OperationStatus) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) QueryStatus(io.cdap.cdap.proto.QueryStatus) CLIService(org.apache.hive.service.cli.CLIService) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 19 with QueryStatus

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;
    }
}
Also used : HandleNotFoundException(io.cdap.cdap.explore.service.HandleNotFoundException) SQLException(java.sql.SQLException) QueryHandle(io.cdap.cdap.proto.QueryHandle) QueryStatus(io.cdap.cdap.proto.QueryStatus) Callable(java.util.concurrent.Callable) ExploreException(io.cdap.cdap.explore.service.ExploreException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 20 with QueryStatus

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;
}
Also used : SQLException(java.sql.SQLException) QueryHandle(io.cdap.cdap.proto.QueryHandle) QueryStatus(io.cdap.cdap.proto.QueryStatus) ServiceUnavailableException(io.cdap.cdap.common.ServiceUnavailableException) ExploreException(io.cdap.cdap.explore.service.ExploreException) SQLException(java.sql.SQLException) IOException(java.io.IOException) UnauthenticatedException(io.cdap.cdap.security.spi.authentication.UnauthenticatedException) HandleNotFoundException(io.cdap.cdap.explore.service.HandleNotFoundException)

Aggregations

QueryStatus (io.cdap.cdap.proto.QueryStatus)36 QueryHandle (io.cdap.cdap.proto.QueryHandle)16 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)14 ExploreException (io.cdap.cdap.explore.service.ExploreException)8 HandleNotFoundException (io.cdap.cdap.explore.service.HandleNotFoundException)6 ColumnDesc (io.cdap.cdap.proto.ColumnDesc)6 OperationStatus (org.apache.hive.service.cli.OperationStatus)6 Test (org.junit.Test)6 QueryResult (io.cdap.cdap.proto.QueryResult)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 SQLException (java.sql.SQLException)4 ServiceUnavailableException (io.cdap.cdap.common.ServiceUnavailableException)2 ExploreExecutionResult (io.cdap.cdap.explore.client.ExploreExecutionResult)2 QueryInfo (io.cdap.cdap.proto.QueryInfo)2 DatasetId (io.cdap.cdap.proto.id.DatasetId)2 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)2 UnauthenticatedException (io.cdap.cdap.security.spi.authentication.UnauthenticatedException)2 IOException (java.io.IOException)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2