use of io.trino.spi.connector.DynamicFilter in project trino by trinodb.
the class TestDynamicFilterService method testDynamicFilter.
@Test
public void testDynamicFilter() {
DynamicFilterService dynamicFilterService = createDynamicFilterService();
DynamicFilterId filterId1 = new DynamicFilterId("df1");
DynamicFilterId filterId2 = new DynamicFilterId("df2");
DynamicFilterId filterId3 = new DynamicFilterId("df3");
SymbolAllocator symbolAllocator = new SymbolAllocator();
Symbol symbol1 = symbolAllocator.newSymbol("DF_SYMBOL1", INTEGER);
Symbol symbol2 = symbolAllocator.newSymbol("DF_SYMBOL2", INTEGER);
Symbol symbol3 = symbolAllocator.newSymbol("DF_SYMBOL3", INTEGER);
Expression df1 = symbol1.toSymbolReference();
Expression df2 = symbol2.toSymbolReference();
Expression df3 = symbol3.toSymbolReference();
QueryId queryId = new QueryId("query");
StageId stageId1 = new StageId(queryId, 1);
StageId stageId2 = new StageId(queryId, 2);
StageId stageId3 = new StageId(queryId, 3);
dynamicFilterService.registerQuery(queryId, session, ImmutableSet.of(filterId1, filterId2, filterId3), ImmutableSet.of(filterId1, filterId2, filterId3), ImmutableSet.of());
dynamicFilterService.stageCannotScheduleMoreTasks(stageId1, 0, 2);
dynamicFilterService.stageCannotScheduleMoreTasks(stageId2, 0, 2);
dynamicFilterService.stageCannotScheduleMoreTasks(stageId3, 0, 2);
DynamicFilter dynamicFilter = dynamicFilterService.createDynamicFilter(queryId, ImmutableList.of(new DynamicFilters.Descriptor(filterId1, df1), new DynamicFilters.Descriptor(filterId2, df2), new DynamicFilters.Descriptor(filterId3, df3)), ImmutableMap.of(symbol1, new TestingColumnHandle("probeColumnA"), symbol2, new TestingColumnHandle("probeColumnA"), symbol3, new TestingColumnHandle("probeColumnB")), symbolAllocator.getTypes());
assertEquals(dynamicFilter.getColumnsCovered(), Set.of(new TestingColumnHandle("probeColumnA"), new TestingColumnHandle("probeColumnB")), "columns covered");
assertTrue(dynamicFilter.getCurrentPredicate().isAll());
assertFalse(dynamicFilter.isComplete());
assertTrue(dynamicFilter.isAwaitable());
// assert initial dynamic filtering stats
DynamicFiltersStats stats = dynamicFilterService.getDynamicFilteringStats(queryId, session);
assertEquals(stats.getTotalDynamicFilters(), 3);
assertEquals(stats.getDynamicFiltersCompleted(), 0);
assertEquals(stats.getLazyDynamicFilters(), 3);
assertEquals(stats.getReplicatedDynamicFilters(), 0);
// dynamic filter should be blocked waiting for tuple domain to be provided
CompletableFuture<?> blockedFuture = dynamicFilter.isBlocked();
assertFalse(blockedFuture.isDone());
dynamicFilterService.addTaskDynamicFilters(new TaskId(stageId1, 0, 0), ImmutableMap.of(filterId1, singleValue(INTEGER, 1L)));
// tuple domain from two tasks are needed for dynamic filter to be narrowed down
assertTrue(dynamicFilter.getCurrentPredicate().isAll());
assertFalse(dynamicFilter.isComplete());
assertTrue(dynamicFilter.isAwaitable());
assertFalse(blockedFuture.isDone());
dynamicFilterService.addTaskDynamicFilters(new TaskId(stageId1, 1, 0), ImmutableMap.of(filterId1, singleValue(INTEGER, 2L)));
// dynamic filter (id1) has been collected as tuple domains from two tasks have been provided
assertEquals(dynamicFilter.getCurrentPredicate(), TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("probeColumnA"), multipleValues(INTEGER, ImmutableList.of(1L, 2L)))));
assertTrue(blockedFuture.isDone());
assertFalse(blockedFuture.isCompletedExceptionally());
stats = dynamicFilterService.getDynamicFilteringStats(queryId, session);
assertEquals(stats.getDynamicFiltersCompleted(), 1);
// there are still more dynamic filters to be collected
assertFalse(dynamicFilter.isComplete());
assertTrue(dynamicFilter.isAwaitable());
blockedFuture = dynamicFilter.isBlocked();
assertFalse(blockedFuture.isDone());
dynamicFilterService.addTaskDynamicFilters(new TaskId(stageId2, 0, 0), ImmutableMap.of(filterId2, singleValue(INTEGER, 2L)));
// tuple domain from two tasks (stage 2) are needed for dynamic filter to be narrowed down
assertEquals(dynamicFilter.getCurrentPredicate(), TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("probeColumnA"), multipleValues(INTEGER, ImmutableList.of(1L, 2L)))));
assertFalse(dynamicFilter.isComplete());
assertTrue(dynamicFilter.isAwaitable());
assertFalse(blockedFuture.isDone());
stats = dynamicFilterService.getDynamicFilteringStats(queryId, session);
assertEquals(stats.getDynamicFiltersCompleted(), 1);
dynamicFilterService.addTaskDynamicFilters(new TaskId(stageId2, 1, 0), ImmutableMap.of(filterId2, singleValue(INTEGER, 3L)));
// dynamic filter (id2) has been collected as tuple domains from two tasks have been provided
assertEquals(dynamicFilter.getCurrentPredicate(), TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("probeColumnA"), singleValue(INTEGER, 2L))));
assertTrue(blockedFuture.isDone());
assertFalse(blockedFuture.isCompletedExceptionally());
stats = dynamicFilterService.getDynamicFilteringStats(queryId, session);
assertEquals(stats.getDynamicFiltersCompleted(), 2);
// there are still more dynamic filters to be collected for columns A and B
assertFalse(dynamicFilter.isComplete());
assertTrue(dynamicFilter.isAwaitable());
blockedFuture = dynamicFilter.isBlocked();
assertFalse(blockedFuture.isDone());
// make sure dynamic filter on just column A is now completed
DynamicFilter dynamicFilterColumnA = dynamicFilterService.createDynamicFilter(queryId, ImmutableList.of(new DynamicFilters.Descriptor(filterId1, df1), new DynamicFilters.Descriptor(filterId2, df2)), ImmutableMap.of(symbol1, new TestingColumnHandle("probeColumnA"), symbol2, new TestingColumnHandle("probeColumnA")), symbolAllocator.getTypes());
assertEquals(dynamicFilterColumnA.getColumnsCovered(), Set.of(new TestingColumnHandle("probeColumnA")), "columns covered");
assertTrue(dynamicFilterColumnA.isComplete());
assertFalse(dynamicFilterColumnA.isAwaitable());
assertTrue(dynamicFilterColumnA.isBlocked().isDone());
assertEquals(dynamicFilterColumnA.getCurrentPredicate(), TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("probeColumnA"), singleValue(INTEGER, 2L))));
dynamicFilterService.addTaskDynamicFilters(new TaskId(stageId3, 0, 0), ImmutableMap.of(filterId3, none(INTEGER)));
// tuple domain from two tasks (stage 3) are needed for dynamic filter to be narrowed down
assertEquals(dynamicFilter.getCurrentPredicate(), TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("probeColumnA"), singleValue(INTEGER, 2L))));
assertFalse(dynamicFilter.isComplete());
assertTrue(dynamicFilter.isAwaitable());
assertFalse(blockedFuture.isDone());
stats = dynamicFilterService.getDynamicFilteringStats(queryId, session);
assertEquals(stats.getDynamicFiltersCompleted(), 2);
dynamicFilterService.addTaskDynamicFilters(new TaskId(stageId3, 1, 0), ImmutableMap.of(filterId3, none(INTEGER)));
// "none" dynamic filter (id3) has been collected for column B as tuple domains from two tasks have been provided
assertEquals(dynamicFilter.getCurrentPredicate(), TupleDomain.none());
assertTrue(blockedFuture.isDone());
assertFalse(blockedFuture.isCompletedExceptionally());
stats = dynamicFilterService.getDynamicFilteringStats(queryId, session);
assertEquals(stats.getDynamicFiltersCompleted(), 3);
assertEquals(stats.getLazyDynamicFilters(), 3);
assertEquals(stats.getReplicatedDynamicFilters(), 0);
assertEquals(ImmutableSet.copyOf(stats.getDynamicFilterDomainStats()), ImmutableSet.of(new DynamicFilterDomainStats(filterId1, getSimplifiedDomainString(1L, 2L, 2, INTEGER)), new DynamicFilterDomainStats(filterId2, getSimplifiedDomainString(2L, 3L, 2, INTEGER)), new DynamicFilterDomainStats(filterId3, Domain.none(INTEGER).toString(session.toConnectorSession()))));
// all dynamic filters have been collected, no need for more requests
assertTrue(dynamicFilter.isComplete());
assertFalse(dynamicFilter.isAwaitable());
assertTrue(dynamicFilter.isBlocked().isDone());
}
use of io.trino.spi.connector.DynamicFilter in project trino by trinodb.
the class TestDynamicFilterService method testDynamicFilterCoercion.
@Test
public void testDynamicFilterCoercion() {
DynamicFilterService dynamicFilterService = createDynamicFilterService();
DynamicFilterId filterId1 = new DynamicFilterId("df1");
SymbolAllocator symbolAllocator = new SymbolAllocator();
Symbol symbol1 = symbolAllocator.newSymbol("DF_SYMBOL1", INTEGER);
Expression df1 = new Cast(symbol1.toSymbolReference(), toSqlType(BIGINT));
QueryId queryId = new QueryId("query");
StageId stageId1 = new StageId(queryId, 1);
dynamicFilterService.registerQuery(queryId, session, ImmutableSet.of(filterId1), ImmutableSet.of(filterId1), ImmutableSet.of());
dynamicFilterService.stageCannotScheduleMoreTasks(stageId1, 0, 1);
DynamicFilter dynamicFilter = dynamicFilterService.createDynamicFilter(queryId, ImmutableList.of(new DynamicFilters.Descriptor(filterId1, df1)), ImmutableMap.of(symbol1, new TestingColumnHandle("probeColumnA")), symbolAllocator.getTypes());
assertEquals(dynamicFilter.getColumnsCovered(), Set.of(new TestingColumnHandle("probeColumnA")), "columns covered");
assertFalse(dynamicFilter.isComplete());
assertTrue(dynamicFilter.getCurrentPredicate().isAll());
dynamicFilterService.addTaskDynamicFilters(new TaskId(stageId1, 0, 0), ImmutableMap.of(filterId1, multipleValues(BIGINT, ImmutableList.of(1L, 2L, 3L))));
assertTrue(dynamicFilter.isComplete());
assertEquals(dynamicFilter.getCurrentPredicate(), TupleDomain.withColumnDomains(ImmutableMap.of(new TestingColumnHandle("probeColumnA"), multipleValues(INTEGER, ImmutableList.of(1L, 2L, 3L)))));
}
use of io.trino.spi.connector.DynamicFilter in project trino by trinodb.
the class TestDynamicFilterService method testDynamicFilterCancellation.
@Test
public void testDynamicFilterCancellation() {
DynamicFilterService dynamicFilterService = createDynamicFilterService();
DynamicFilterId filterId = new DynamicFilterId("df");
SymbolAllocator symbolAllocator = new SymbolAllocator();
Symbol symbol1 = symbolAllocator.newSymbol("DF_SYMBOL1", INTEGER);
Expression df1 = symbol1.toSymbolReference();
QueryId queryId = new QueryId("query");
StageId stageId = new StageId(queryId, 0);
dynamicFilterService.registerQuery(queryId, session, ImmutableSet.of(filterId), ImmutableSet.of(filterId), ImmutableSet.of());
dynamicFilterService.stageCannotScheduleMoreTasks(stageId, 0, 2);
ColumnHandle column = new TestingColumnHandle("probeColumnA");
DynamicFilter dynamicFilter = dynamicFilterService.createDynamicFilter(queryId, ImmutableList.of(new DynamicFilters.Descriptor(filterId, df1)), ImmutableMap.of(symbol1, column), symbolAllocator.getTypes());
assertFalse(dynamicFilter.isBlocked().isDone());
assertFalse(dynamicFilter.isComplete());
assertEquals(dynamicFilter.getCurrentPredicate(), TupleDomain.all());
dynamicFilterService.addTaskDynamicFilters(new TaskId(stageId, 0, 0), ImmutableMap.of(filterId, singleValue(INTEGER, 1L)));
assertEquals(dynamicFilter.getCurrentPredicate(), TupleDomain.all());
// DynamicFilter future cancellation should not affect DynamicFilterService
CompletableFuture<?> isBlocked = dynamicFilter.isBlocked();
assertFalse(isBlocked.isDone());
assertFalse(isBlocked.cancel(false));
assertFalse(dynamicFilter.isBlocked().isDone());
assertFalse(dynamicFilter.isComplete());
dynamicFilterService.addTaskDynamicFilters(new TaskId(stageId, 1, 0), ImmutableMap.of(filterId, singleValue(INTEGER, 2L)));
assertTrue(isBlocked.isDone());
assertTrue(dynamicFilter.isComplete());
assertEquals(dynamicFilter.getCurrentPredicate(), TupleDomain.withColumnDomains(ImmutableMap.of(column, multipleValues(INTEGER, ImmutableList.of(1L, 2L)))));
}
use of io.trino.spi.connector.DynamicFilter in project trino by trinodb.
the class TestDynamicFilterService method testShortCircuitOnAllTupleDomain.
@Test
public void testShortCircuitOnAllTupleDomain() {
DynamicFilterService dynamicFilterService = createDynamicFilterService();
DynamicFilterId filterId1 = new DynamicFilterId("df1");
SymbolAllocator symbolAllocator = new SymbolAllocator();
Symbol symbol1 = symbolAllocator.newSymbol("DF_SYMBOL1", INTEGER);
Expression df1 = symbol1.toSymbolReference();
QueryId queryId = new QueryId("query");
StageId stageId1 = new StageId(queryId, 1);
dynamicFilterService.registerQuery(queryId, session, ImmutableSet.of(filterId1), ImmutableSet.of(filterId1), ImmutableSet.of());
dynamicFilterService.stageCannotScheduleMoreTasks(stageId1, 0, 2);
DynamicFilter dynamicFilter = dynamicFilterService.createDynamicFilter(queryId, ImmutableList.of(new DynamicFilters.Descriptor(filterId1, df1)), ImmutableMap.of(symbol1, new TestingColumnHandle("probeColumnA")), symbolAllocator.getTypes());
// dynamic filter is initially blocked
assertTrue(dynamicFilter.getCurrentPredicate().isAll());
assertFalse(dynamicFilter.isComplete());
assertFalse(dynamicFilter.isBlocked().isDone());
dynamicFilterService.addTaskDynamicFilters(new TaskId(stageId1, 1, 0), ImmutableMap.of(filterId1, Domain.all(INTEGER)));
// dynamic filter should be unblocked and completed
assertTrue(dynamicFilter.getCurrentPredicate().isAll());
assertTrue(dynamicFilter.isComplete());
assertTrue(dynamicFilter.isBlocked().isDone());
}
use of io.trino.spi.connector.DynamicFilter in project trino by trinodb.
the class TestHttpRemoteTask method testOutboundDynamicFilters.
@Test(timeOut = 30_000)
public void testOutboundDynamicFilters() 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());
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 filter is collected
CompletableFuture<?> future = dynamicFilter.isBlocked();
dynamicFilterService.addTaskDynamicFilters(new TaskId(new StageId(queryId.getId(), 1), 1, 0), ImmutableMap.of(filterId1, Domain.singleValue(BIGINT, 1L)));
future.get();
assertEquals(dynamicFilter.getCurrentPredicate(), TupleDomain.withColumnDomains(ImmutableMap.of(handle1, Domain.singleValue(BIGINT, 1L))));
// Create remote task after dynamic filter is created to simulate new nodes joining
HttpRemoteTaskFactory httpRemoteTaskFactory = createHttpRemoteTaskFactory(testingTaskResource, dynamicFilterService);
RemoteTask remoteTask = createRemoteTask(httpRemoteTaskFactory, ImmutableSet.of(filterId1, filterId2));
testingTaskResource.setInitialTaskInfo(remoteTask.getTaskInfo());
remoteTask.start();
assertEventually(new Duration(10, SECONDS), () -> assertEquals(testingTaskResource.getDynamicFiltersSentCounter(), 1L));
assertEquals(testingTaskResource.getCreateOrUpdateCounter(), 1L);
// schedule a couple of splits to trigger task updates
addSplit(remoteTask, testingTaskResource, 1);
addSplit(remoteTask, testingTaskResource, 2);
// make sure dynamic filter was sent in task updates only once
assertEquals(testingTaskResource.getDynamicFiltersSentCounter(), 1L);
assertEquals(testingTaskResource.getCreateOrUpdateCounter(), 3L);
assertEquals(testingTaskResource.getLatestDynamicFilterFromCoordinator(), ImmutableMap.of(filterId1, Domain.singleValue(BIGINT, 1L)));
future = dynamicFilter.isBlocked();
dynamicFilterService.addTaskDynamicFilters(new TaskId(new StageId(queryId.getId(), 1), 1, 0), 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))));
// dynamic filter should be sent even though there were no further splits scheduled
assertEventually(new Duration(10, SECONDS), () -> assertEquals(testingTaskResource.getDynamicFiltersSentCounter(), 2L));
assertEquals(testingTaskResource.getCreateOrUpdateCounter(), 4L);
// previously sent dynamic filter should not be repeated
assertEquals(testingTaskResource.getLatestDynamicFilterFromCoordinator(), ImmutableMap.of(filterId2, Domain.singleValue(BIGINT, 2L)));
httpRemoteTaskFactory.stop();
dynamicFilterService.stop();
}
Aggregations