Search in sources :

Example 16 with QueryStatus

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

Example 17 with QueryStatus

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

Example 18 with QueryStatus

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

Aggregations

QueryStatus (co.cask.cdap.proto.QueryStatus)18 QueryHandle (co.cask.cdap.proto.QueryHandle)8 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)7 ExploreException (co.cask.cdap.explore.service.ExploreException)4 HandleNotFoundException (co.cask.cdap.explore.service.HandleNotFoundException)3 ColumnDesc (co.cask.cdap.proto.ColumnDesc)3 OperationStatus (org.apache.hive.service.cli.OperationStatus)3 Test (org.junit.Test)3 QueryResult (co.cask.cdap.proto.QueryResult)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 SQLException (java.sql.SQLException)2 ServiceUnavailableException (co.cask.cdap.common.ServiceUnavailableException)1 UnauthenticatedException (co.cask.cdap.common.UnauthenticatedException)1 ExploreExecutionResult (co.cask.cdap.explore.client.ExploreExecutionResult)1 QueryInfo (co.cask.cdap.proto.QueryInfo)1 DatasetId (co.cask.cdap.proto.id.DatasetId)1 NamespaceId (co.cask.cdap.proto.id.NamespaceId)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1