Search in sources :

Example 11 with QueryStatus

use of io.cdap.cdap.proto.QueryStatus in project cdap by caskdata.

the class CLITestBase method assertExploreQuerySuccess.

private void assertExploreQuerySuccess(ListenableFuture<ExploreExecutionResult> dbCreationFuture) throws Exception {
    ExploreExecutionResult exploreExecutionResult = dbCreationFuture.get(10, TimeUnit.SECONDS);
    QueryStatus status = exploreExecutionResult.getStatus();
    Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
}
Also used : ExploreExecutionResult(io.cdap.cdap.explore.client.ExploreExecutionResult) QueryStatus(io.cdap.cdap.proto.QueryStatus)

Example 12 with QueryStatus

use of io.cdap.cdap.proto.QueryStatus in project cdap by cdapio.

the class CLITestBase method assertExploreQuerySuccess.

private void assertExploreQuerySuccess(ListenableFuture<ExploreExecutionResult> dbCreationFuture) throws Exception {
    ExploreExecutionResult exploreExecutionResult = dbCreationFuture.get(10, TimeUnit.SECONDS);
    QueryStatus status = exploreExecutionResult.getStatus();
    Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
}
Also used : ExploreExecutionResult(io.cdap.cdap.explore.client.ExploreExecutionResult) QueryStatus(io.cdap.cdap.proto.QueryStatus)

Example 13 with QueryStatus

use of io.cdap.cdap.proto.QueryStatus in project cdap by cdapio.

the class BaseHiveExploreService method nextResults.

@Override
public List<QueryResult> nextResults(QueryHandle handle, int size) throws ExploreException, HandleNotFoundException, SQLException {
    startAndWait();
    InactiveOperationInfo inactiveOperationInfo = inactiveHandleCache.getIfPresent(handle);
    if (inactiveOperationInfo != null) {
        // Operation has been made inactive, so all results should have been fetched already - return empty list.
        LOG.trace("Returning empty result for inactive handle {}", handle);
        return ImmutableList.of();
    }
    try {
        List<QueryResult> results = fetchNextResults(handle, size);
        QueryStatus status = getStatus(handle);
        if (results.isEmpty() && status.getStatus() == QueryStatus.OpStatus.FINISHED) {
            // Since operation has fetched all the results, handle can be timed out aggressively.
            timeoutAggressively(handle, getResultSchema(handle), status);
        }
        return results;
    } catch (HiveSQLException e) {
        throw getSqlException(e);
    }
}
Also used : QueryResult(io.cdap.cdap.proto.QueryResult) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) QueryStatus(io.cdap.cdap.proto.QueryStatus)

Example 14 with QueryStatus

use of io.cdap.cdap.proto.QueryStatus in project cdap by cdapio.

the class BaseHiveExploreService method getStatus.

@Override
public QueryStatus getStatus(QueryHandle handle) throws ExploreException, HandleNotFoundException, SQLException {
    startAndWait();
    InactiveOperationInfo inactiveOperationInfo = inactiveHandleCache.getIfPresent(handle);
    if (inactiveOperationInfo != null) {
        // Operation has been made inactive, so return the saved status.
        LOG.trace("Returning saved status for inactive handle {}", handle);
        return inactiveOperationInfo.getStatus();
    }
    try {
        // Fetch status from Hive
        QueryStatus status = fetchStatus(getActiveOperationInfo(handle));
        LOG.trace("Status of handle {} is {}", handle, status);
        // No results or error, so can be timed out aggressively
        if (status.getStatus() == QueryStatus.OpStatus.FINISHED && !status.hasResults()) {
            // In case of a query that writes to a Dataset, we will always fall into this condition,
            // and timing out aggressively will also close the transaction and make the writes visible
            timeoutAggressively(handle, getResultSchema(handle), status);
        } else if (status.getStatus() == QueryStatus.OpStatus.ERROR) {
            // getResultSchema will fail if the query is in error
            timeoutAggressively(handle, ImmutableList.<ColumnDesc>of(), status);
        }
        return status;
    } catch (HiveSQLException e) {
        throw getSqlException(e);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) ColumnDesc(io.cdap.cdap.proto.ColumnDesc) QueryStatus(io.cdap.cdap.proto.QueryStatus)

Example 15 with QueryStatus

use of io.cdap.cdap.proto.QueryStatus in project cdap by cdapio.

the class BaseHiveExploreService method execute.

@Override
public QueryHandle execute(NamespaceId namespace, String[] statements) throws ExploreException, SQLException {
    Preconditions.checkArgument(statements.length > 0, "There must be at least one statement");
    startAndWait();
    try {
        SessionHandle sessionHandle = null;
        OperationHandle operationHandle = null;
        Map<String, String> sessionConf = startSession(namespace);
        String database = getHiveDatabase(namespace.getNamespace());
        try {
            sessionHandle = openHiveSession(sessionConf);
            // Switch database to the one being passed in.
            setCurrentDatabase(database);
            // synchronously execute all but the last statement
            for (int i = 0; i < statements.length - 1; i++) {
                String statement = statements[i];
                LOG.trace("Executing statement synchronously: {}", statement);
                operationHandle = executeSync(sessionHandle, statement);
                QueryStatus status = doFetchStatus(operationHandle);
                if (QueryStatus.OpStatus.ERROR == status.getStatus()) {
                    throw new HiveSQLException(status.getErrorMessage(), status.getSqlState());
                }
                if (QueryStatus.OpStatus.FINISHED != status.getStatus()) {
                    throw new ExploreException("Expected operation status FINISHED for statement '{}' but received " + status.getStatus());
                }
            }
            String statement = statements[statements.length - 1];
            operationHandle = executeAsync(sessionHandle, statement);
            QueryHandle handle = saveReadWriteOperation(operationHandle, sessionHandle, sessionConf, statement, database);
            LOG.trace("Executing statement: {} with handle {}", statement, handle);
            return handle;
        } catch (Throwable e) {
            closeInternal(getQueryHandle(sessionConf), new ReadWriteOperationInfo(sessionHandle, operationHandle, sessionConf, "", database));
            throw e;
        }
    } catch (HiveSQLException e) {
        throw getSqlException(e);
    } catch (Throwable e) {
        throw new ExploreException(e);
    }
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) SessionHandle(org.apache.hive.service.cli.SessionHandle) QueryHandle(io.cdap.cdap.proto.QueryHandle) OperationHandle(org.apache.hive.service.cli.OperationHandle) QueryStatus(io.cdap.cdap.proto.QueryStatus) ExploreException(io.cdap.cdap.explore.service.ExploreException)

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