Search in sources :

Example 6 with DynamicFilterService

use of io.trino.server.DynamicFilterService in project trino by trinodb.

the class TestHttpRemoteTask method testDynamicFilters.

@Test(timeOut = 30000)
public void testDynamicFilters() throws Exception {
    DynamicFilterId filterId1 = new DynamicFilterId("df1");
    DynamicFilterId filterId2 = new DynamicFilterId("df2");
    SymbolAllocator symbolAllocator = new SymbolAllocator();
    Symbol symbol1 = symbolAllocator.newSymbol("DF_SYMBOL1", BIGINT);
    Symbol symbol2 = symbolAllocator.newSymbol("DF_SYMBOL2", BIGINT);
    SymbolReference df1 = symbol1.toSymbolReference();
    SymbolReference df2 = symbol2.toSymbolReference();
    ColumnHandle handle1 = new TestingColumnHandle("column1");
    ColumnHandle handle2 = new TestingColumnHandle("column2");
    QueryId queryId = new QueryId("test");
    TestingTaskResource testingTaskResource = new TestingTaskResource(new AtomicLong(System.nanoTime()), FailureScenario.NO_FAILURE);
    DynamicFilterService dynamicFilterService = new DynamicFilterService(PLANNER_CONTEXT.getMetadata(), PLANNER_CONTEXT.getFunctionManager(), new TypeOperators(), newDirectExecutorService());
    HttpRemoteTaskFactory httpRemoteTaskFactory = createHttpRemoteTaskFactory(testingTaskResource, dynamicFilterService);
    RemoteTask remoteTask = createRemoteTask(httpRemoteTaskFactory, ImmutableSet.of());
    Map<DynamicFilterId, Domain> initialDomain = ImmutableMap.of(filterId1, Domain.singleValue(BIGINT, 1L));
    testingTaskResource.setInitialTaskInfo(remoteTask.getTaskInfo());
    testingTaskResource.setDynamicFilterDomains(new VersionedDynamicFilterDomains(1L, initialDomain));
    dynamicFilterService.registerQuery(queryId, TEST_SESSION, ImmutableSet.of(filterId1, filterId2), ImmutableSet.of(filterId1, filterId2), ImmutableSet.of());
    dynamicFilterService.stageCannotScheduleMoreTasks(new StageId(queryId, 1), 0, 1);
    DynamicFilter dynamicFilter = dynamicFilterService.createDynamicFilter(queryId, ImmutableList.of(new DynamicFilters.Descriptor(filterId1, df1), new DynamicFilters.Descriptor(filterId2, df2)), ImmutableMap.of(symbol1, handle1, symbol2, handle2), symbolAllocator.getTypes());
    // make sure initial dynamic filters are collected
    CompletableFuture<?> future = dynamicFilter.isBlocked();
    remoteTask.start();
    future.get();
    assertEquals(dynamicFilter.getCurrentPredicate(), TupleDomain.withColumnDomains(ImmutableMap.of(handle1, Domain.singleValue(BIGINT, 1L))));
    assertEquals(testingTaskResource.getDynamicFiltersFetchCounter(), 1);
    // make sure dynamic filters are not collected for every status update
    assertEventually(new Duration(15, SECONDS), () -> assertGreaterThanOrEqual(testingTaskResource.getStatusFetchCounter(), 3L));
    assertEquals(testingTaskResource.getDynamicFiltersFetchCounter(), 1L, testingTaskResource.getDynamicFiltersFetchRequests().toString());
    future = dynamicFilter.isBlocked();
    testingTaskResource.setDynamicFilterDomains(new VersionedDynamicFilterDomains(2L, ImmutableMap.of(filterId2, Domain.singleValue(BIGINT, 2L))));
    future.get();
    assertEquals(dynamicFilter.getCurrentPredicate(), TupleDomain.withColumnDomains(ImmutableMap.of(handle1, Domain.singleValue(BIGINT, 1L), handle2, Domain.singleValue(BIGINT, 2L))));
    assertEquals(testingTaskResource.getDynamicFiltersFetchCounter(), 2L, testingTaskResource.getDynamicFiltersFetchRequests().toString());
    assertGreaterThanOrEqual(testingTaskResource.getStatusFetchCounter(), 4L);
    httpRemoteTaskFactory.stop();
    dynamicFilterService.stop();
}
Also used : SymbolAllocator(io.trino.sql.planner.SymbolAllocator) TestingColumnHandle(io.trino.spi.connector.TestingColumnHandle) ColumnHandle(io.trino.spi.connector.ColumnHandle) DynamicFilter(io.trino.spi.connector.DynamicFilter) Symbol(io.trino.sql.planner.Symbol) SymbolReference(io.trino.sql.tree.SymbolReference) QueryId(io.trino.spi.QueryId) StageId(io.trino.execution.StageId) RemoteTask(io.trino.execution.RemoteTask) Duration(io.airlift.units.Duration) VersionedDynamicFilterDomains(io.trino.execution.DynamicFiltersCollector.VersionedDynamicFilterDomains) TestingColumnHandle(io.trino.spi.connector.TestingColumnHandle) AtomicLong(java.util.concurrent.atomic.AtomicLong) HttpRemoteTaskFactory(io.trino.server.HttpRemoteTaskFactory) DynamicFilterService(io.trino.server.DynamicFilterService) Domain(io.trino.spi.predicate.Domain) TupleDomain(io.trino.spi.predicate.TupleDomain) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) TypeOperators(io.trino.spi.type.TypeOperators) Test(org.testng.annotations.Test)

Aggregations

DynamicFilterService (io.trino.server.DynamicFilterService)6 Duration (io.airlift.units.Duration)5 Test (org.testng.annotations.Test)5 DynamicFilterConfig (io.trino.execution.DynamicFilterConfig)4 RemoteTask (io.trino.execution.RemoteTask)4 TableExecuteContextManager (io.trino.execution.TableExecuteContextManager)4 ConnectorAwareSplitSource (io.trino.split.ConnectorAwareSplitSource)4 NodeTaskMap (io.trino.execution.NodeTaskMap)3 PipelinedStageExecution.createPipelinedStageExecution (io.trino.execution.scheduler.PipelinedStageExecution.createPipelinedStageExecution)3 SourcePartitionedScheduler.newSourcePartitionedSchedulerAsStageScheduler (io.trino.execution.scheduler.SourcePartitionedScheduler.newSourcePartitionedSchedulerAsStageScheduler)3 DynamicFilter (io.trino.spi.connector.DynamicFilter)3 PlanFragment (io.trino.sql.planner.PlanFragment)3 Symbol (io.trino.sql.planner.Symbol)3 SymbolAllocator (io.trino.sql.planner.SymbolAllocator)3 MockRemoteTask (io.trino.execution.MockRemoteTaskFactory.MockRemoteTask)2 PartitionedSplitsInfo (io.trino.execution.PartitionedSplitsInfo)2 StageId (io.trino.execution.StageId)2 InMemoryNodeManager (io.trino.metadata.InMemoryNodeManager)2 InternalNode (io.trino.metadata.InternalNode)2 HttpRemoteTaskFactory (io.trino.server.HttpRemoteTaskFactory)2