Search in sources :

Example 1 with QueryStatus

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

the class BaseHiveExploreServiceTest method waitForCompletionStatus.

protected static QueryStatus waitForCompletionStatus(QueryHandle handle, long sleepTime, TimeUnit timeUnit, int maxTries) throws ExploreException, HandleNotFoundException, InterruptedException, SQLException {
    QueryStatus status;
    int tries = 0;
    do {
        timeUnit.sleep(sleepTime);
        status = exploreService.getStatus(handle);
        if (++tries > maxTries) {
            break;
        }
    } while (!status.getStatus().isDone());
    return status;
}
Also used : QueryStatus(io.cdap.cdap.proto.QueryStatus)

Example 2 with QueryStatus

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

the class HiveExploreServiceTimeoutTest method testTimeoutNoResults.

@Test
public void testTimeoutNoResults() throws Exception {
    Set<Long> beforeTxns = transactionManager.getCurrentState().getInProgress().keySet();
    QueryHandle handle = exploreService.execute(NAMESPACE_ID, "drop table if exists not_existing_table_name");
    Set<Long> queryTxns = Sets.difference(transactionManager.getCurrentState().getInProgress().keySet(), beforeTxns);
    Assert.assertFalse(queryTxns.isEmpty());
    QueryStatus status = waitForCompletionStatus(handle, 200, TimeUnit.MILLISECONDS, 20);
    Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
    Assert.assertFalse(status.hasResults());
    List<ColumnDesc> schema = exploreService.getResultSchema(handle);
    // Sleep for some time for txn to get closed
    TimeUnit.SECONDS.sleep(1);
    // Make sure that the transaction got closed
    Assert.assertEquals(ImmutableSet.<Long>of(), Sets.intersection(queryTxns, transactionManager.getCurrentState().getInProgress().keySet()).immutableCopy());
    // Check if calls using inactive handle still work
    Assert.assertEquals(status, exploreService.getStatus(handle));
    Assert.assertEquals(schema, exploreService.getResultSchema(handle));
    exploreService.close(handle);
    // Sleep for timeout to happen
    TimeUnit.SECONDS.sleep(INACTIVE_OPERATION_TIMEOUT_SECS + 3);
    try {
        exploreService.getStatus(handle);
        Assert.fail("Should throw HandleNotFoundException due to operation cleanup");
    } catch (HandleNotFoundException e) {
    // Expected exception due to timeout
    }
}
Also used : QueryHandle(io.cdap.cdap.proto.QueryHandle) ColumnDesc(io.cdap.cdap.proto.ColumnDesc) QueryStatus(io.cdap.cdap.proto.QueryStatus) Test(org.junit.Test)

Example 3 with QueryStatus

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

the class HiveExploreServiceTimeoutTest method testTimeoutFetchAllResults.

@Test
public void testTimeoutFetchAllResults() throws Exception {
    Set<Long> beforeTxns = transactionManager.getCurrentState().getInProgress().keySet();
    QueryHandle handle = exploreService.execute(NAMESPACE_ID, "select key, value from " + MY_TABLE_NAME);
    Set<Long> queryTxns = Sets.difference(transactionManager.getCurrentState().getInProgress().keySet(), beforeTxns);
    Assert.assertFalse(queryTxns.isEmpty());
    QueryStatus status = waitForCompletionStatus(handle, 200, TimeUnit.MILLISECONDS, 20);
    Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
    Assert.assertTrue(status.hasResults());
    List<ColumnDesc> schema = exploreService.getResultSchema(handle);
    // noinspection StatementWithEmptyBody
    while (!exploreService.nextResults(handle, 100).isEmpty()) {
    // nothing to do
    }
    // Sleep for some time for txn to get closed
    TimeUnit.SECONDS.sleep(1);
    // Make sure that the transaction got closed
    Assert.assertEquals(ImmutableSet.<Long>of(), Sets.intersection(queryTxns, transactionManager.getCurrentState().getInProgress().keySet()).immutableCopy());
    // Check if calls using inactive handle still work
    Assert.assertEquals(status, exploreService.getStatus(handle));
    Assert.assertEquals(schema, exploreService.getResultSchema(handle));
    exploreService.close(handle);
    // Sleep for timeout to happen
    TimeUnit.SECONDS.sleep(INACTIVE_OPERATION_TIMEOUT_SECS + 3);
    try {
        exploreService.getStatus(handle);
        Assert.fail("Should throw HandleNotFoundException due to operation cleanup");
    } catch (HandleNotFoundException e) {
    // Expected exception due to timeout
    }
}
Also used : QueryHandle(io.cdap.cdap.proto.QueryHandle) ColumnDesc(io.cdap.cdap.proto.ColumnDesc) QueryStatus(io.cdap.cdap.proto.QueryStatus) Test(org.junit.Test)

Example 4 with QueryStatus

use of io.cdap.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(io.cdap.cdap.proto.QueryStatus)

Example 5 with QueryStatus

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

Aggregations

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