Search in sources :

Example 6 with QueryStatus

use of co.cask.cdap.proto.QueryStatus in project cdap by caskdata.

the class CLIMainTest method assertExploreQuerySuccess.

private static 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(co.cask.cdap.explore.client.ExploreExecutionResult) QueryStatus(co.cask.cdap.proto.QueryStatus)

Example 7 with QueryStatus

use of co.cask.cdap.proto.QueryStatus in project cdap by caskdata.

the class InMemoryExploreServiceTest method runCommand.

private static void runCommand(String namespace, String command, boolean expectedHasResult, List<ColumnDesc> expectedColumnDescs, List<QueryResult> expectedResults) throws Exception {
    QueryHandle handle = exploreService.execute(new NamespaceId(namespace), command);
    QueryStatus status = waitForCompletionStatus(handle);
    Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
    Assert.assertEquals(expectedHasResult, status.hasResults());
    Assert.assertEquals(expectedColumnDescs, exploreService.getResultSchema(handle));
    Assert.assertEquals(expectedResults.toString(), trimColumnValues(exploreService.nextResults(handle, 100)).toString());
    exploreService.close(handle);
}
Also used : NamespaceId(co.cask.cdap.proto.id.NamespaceId) QueryHandle(co.cask.cdap.proto.QueryHandle) QueryStatus(co.cask.cdap.proto.QueryStatus)

Example 8 with QueryStatus

use of co.cask.cdap.proto.QueryStatus in project cdap by caskdata.

the class InMemoryExploreServiceTest method waitForCompletionStatus.

private static QueryStatus waitForCompletionStatus(QueryHandle handle) throws Exception {
    QueryStatus status;
    do {
        TimeUnit.MILLISECONDS.sleep(200);
        status = exploreService.getStatus(handle);
    } while (status.getStatus() == QueryStatus.OpStatus.RUNNING || status.getStatus() == QueryStatus.OpStatus.PENDING);
    return status;
}
Also used : QueryStatus(co.cask.cdap.proto.QueryStatus)

Example 9 with QueryStatus

use of co.cask.cdap.proto.QueryStatus in project cdap by caskdata.

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(co.cask.cdap.proto.QueryResult) HiveSQLException(org.apache.hive.service.cli.HiveSQLException) QueryStatus(co.cask.cdap.proto.QueryStatus)

Example 10 with QueryStatus

use of co.cask.cdap.proto.QueryStatus in project cdap by caskdata.

the class BaseHiveExploreService method fetchStatus.

protected QueryStatus fetchStatus(OperationInfo operationInfo) throws ExploreException, HandleNotFoundException, HiveSQLException {
    QueryStatus queryStatus;
    try {
        queryStatus = doFetchStatus(operationInfo.getOperationHandle());
        if (QueryStatus.OpStatus.ERROR.equals(queryStatus.getStatus()) && queryStatus.getErrorMessage() == null) {
            queryStatus = new QueryStatus("Operation failed. See the log for more details.", null);
        }
    } catch (HiveSQLException e) {
        // it means that query execution failed, but we can successfully retrieve the status.
        if (e.getSQLState() != null) {
            queryStatus = new QueryStatus(e.getMessage(), e.getSQLState());
        } else {
            // this is an internal error - we are not able to retrieve the status
            throw new ExploreException(e.getMessage(), e);
        }
    }
    operationInfo.setStatus(queryStatus);
    return queryStatus;
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) QueryStatus(co.cask.cdap.proto.QueryStatus) 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