Search in sources :

Example 1 with QueryPrerequisitesContext

use of com.facebook.presto.spi.prerequisites.QueryPrerequisitesContext in project presto by prestodb.

the class TestLocalDispatchQuery method testPrerequisitesQueryFinishedCalled.

@Test
public void testPrerequisitesQueryFinishedCalled() {
    QueryStateMachine stateMachine = createStateMachine();
    CountingEventListener eventListener = new CountingEventListener();
    CompletableFuture<?> prequisitesFuture = new CompletableFuture<>();
    AtomicBoolean queryFinishedCalled = new AtomicBoolean();
    LocalDispatchQuery query = new LocalDispatchQuery(stateMachine, createQueryMonitor(eventListener), immediateFuture(null), createClusterSizeMonitor(0), directExecutor(), dispatchQuery -> {
    }, execution -> {
    }, false, new QueryPrerequisites() {

        @Override
        public CompletableFuture<?> waitForPrerequisites(QueryId queryId, QueryPrerequisitesContext context, WarningCollector warningCollector) {
            return prequisitesFuture;
        }

        @Override
        public void queryFinished(QueryId queryId) {
            queryFinishedCalled.set(true);
        }
    });
    assertEquals(query.getBasicQueryInfo().getState(), WAITING_FOR_PREREQUISITES);
    assertFalse(eventListener.getQueryCompletedEvent().isPresent());
    query.startWaitingForPrerequisites();
    prequisitesFuture.complete(null);
    query.fail(new PrestoException(ABANDONED_QUERY, "foo"));
    assertTrue(queryFinishedCalled.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TaskTestUtils.createQueryStateMachine(com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine) QueryStateMachine(com.facebook.presto.execution.QueryStateMachine) CompletableFuture(java.util.concurrent.CompletableFuture) QueryPrerequisitesContext(com.facebook.presto.spi.prerequisites.QueryPrerequisitesContext) QueryId(com.facebook.presto.spi.QueryId) PrestoException(com.facebook.presto.spi.PrestoException) QueryPrerequisites(com.facebook.presto.spi.prerequisites.QueryPrerequisites) WarningCollector(com.facebook.presto.spi.WarningCollector) Test(org.testng.annotations.Test)

Example 2 with QueryPrerequisitesContext

use of com.facebook.presto.spi.prerequisites.QueryPrerequisitesContext in project presto by prestodb.

the class LocalDispatchQuery method startWaitingForPrerequisites.

@Override
public void startWaitingForPrerequisites() {
    // start waiting for prerequisites
    if (isDone()) {
        return;
    }
    try {
        Session session = stateMachine.getSession();
        CompletableFuture<?> prerequisitesFuture = queryPrerequisites.waitForPrerequisites(stateMachine.getQueryId(), new QueryPrerequisitesContext(session.getCatalog(), session.getSchema(), stateMachine.getBasicQueryInfo(Optional.empty()).getQuery(), session.getSystemProperties(), session.getConnectorProperties()), warningCollector);
        addStateChangeListener(state -> {
            if (state.isDone()) {
                queryPrerequisites.queryFinished(stateMachine.getQueryId());
                if (!prerequisitesFuture.isDone()) {
                    prerequisitesFuture.cancel(true);
                }
            }
        });
        prerequisitesFuture.whenCompleteAsync((result, throwable) -> {
            if (throwable != null) {
                fail(throwable);
                return;
            }
            queueQuery();
        }, queryExecutor);
    } catch (Throwable t) {
        fail(t);
        throw t;
    }
}
Also used : QueryPrerequisitesContext(com.facebook.presto.spi.prerequisites.QueryPrerequisitesContext) Session(com.facebook.presto.Session)

Aggregations

QueryPrerequisitesContext (com.facebook.presto.spi.prerequisites.QueryPrerequisitesContext)2 Session (com.facebook.presto.Session)1 QueryStateMachine (com.facebook.presto.execution.QueryStateMachine)1 TaskTestUtils.createQueryStateMachine (com.facebook.presto.execution.TaskTestUtils.createQueryStateMachine)1 PrestoException (com.facebook.presto.spi.PrestoException)1 QueryId (com.facebook.presto.spi.QueryId)1 WarningCollector (com.facebook.presto.spi.WarningCollector)1 QueryPrerequisites (com.facebook.presto.spi.prerequisites.QueryPrerequisites)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.testng.annotations.Test)1