Search in sources :

Example 71 with DynamicFilterId

use of io.trino.sql.planner.plan.DynamicFilterId in project trino by trinodb.

the class TestDynamicFiltersChecker method testUnsupportedDynamicFilterExpression.

@Test
public void testUnsupportedDynamicFilterExpression() {
    PlanNode root = builder.output(ImmutableList.of(), ImmutableList.of(), builder.join(INNER, builder.filter(createDynamicFilterExpression(TEST_SESSION, metadata, new DynamicFilterId("DF"), BIGINT, expression("LINEITEM_OK + BIGINT'1'")), lineitemTableScanNode), ordersTableScanNode, ImmutableList.of(new JoinNode.EquiJoinClause(lineitemOrderKeySymbol, ordersOrderKeySymbol)), ImmutableList.of(lineitemOrderKeySymbol), ImmutableList.of(ordersOrderKeySymbol), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(new DynamicFilterId("DF"), ordersOrderKeySymbol)));
    assertThatThrownBy(() -> validatePlan(root)).isInstanceOf(VerifyException.class).hasMessageMatching("Dynamic filter expression \\(\"LINEITEM_OK\" \\+ BIGINT '1'\\) must be a SymbolReference or a CAST of SymbolReference.");
}
Also used : PlanNode(io.trino.sql.planner.plan.PlanNode) VerifyException(com.google.common.base.VerifyException) JoinNode(io.trino.sql.planner.plan.JoinNode) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Example 72 with DynamicFilterId

use of io.trino.sql.planner.plan.DynamicFilterId in project trino by trinodb.

the class TestDynamicFiltersChecker method testUnmatchedNestedDynamicFilter.

@Test
public void testUnmatchedNestedDynamicFilter() {
    PlanNode root = builder.output(ImmutableList.of(), ImmutableList.of(), builder.join(INNER, ordersTableScanNode, builder.filter(combineConjuncts(metadata, combineDisjuncts(metadata, expression("LINEITEM_OK IS NULL"), createDynamicFilterExpression(TEST_SESSION, metadata, new DynamicFilterId("DF"), BIGINT, lineitemOrderKeySymbol.toSymbolReference())), combineDisjuncts(metadata, expression("LINEITEM_OK IS NOT NULL"), createDynamicFilterExpression(TEST_SESSION, metadata, new DynamicFilterId("DF"), BIGINT, lineitemOrderKeySymbol.toSymbolReference()))), lineitemTableScanNode), ImmutableList.of(new JoinNode.EquiJoinClause(ordersOrderKeySymbol, lineitemOrderKeySymbol)), ImmutableList.of(ordersOrderKeySymbol), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of()));
    assertThatThrownBy(() -> validatePlan(root)).isInstanceOf(VerifyException.class).hasMessageMatching("All consumed dynamic filters could not be matched with a join/semi-join.");
}
Also used : PlanNode(io.trino.sql.planner.plan.PlanNode) VerifyException(com.google.common.base.VerifyException) JoinNode(io.trino.sql.planner.plan.JoinNode) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Example 73 with DynamicFilterId

use of io.trino.sql.planner.plan.DynamicFilterId in project trino by trinodb.

the class LocalDynamicFilterConsumer method create.

public static LocalDynamicFilterConsumer create(JoinNode planNode, List<Type> buildSourceTypes, int partitionCount, Set<DynamicFilterId> collectedFilters) {
    checkArgument(!planNode.getDynamicFilters().isEmpty(), "Join node dynamicFilters is empty.");
    checkArgument(!collectedFilters.isEmpty(), "Collected dynamic filters set is empty");
    checkArgument(planNode.getDynamicFilters().keySet().containsAll(collectedFilters), "Collected dynamic filters set is not subset of join dynamic filters");
    PlanNode buildNode = planNode.getRight();
    Map<DynamicFilterId, Integer> buildChannels = planNode.getDynamicFilters().entrySet().stream().filter(entry -> collectedFilters.contains(entry.getKey())).collect(toImmutableMap(// Dynamic filter ID
    Map.Entry::getKey, // Build-side channel index
    entry -> {
        Symbol buildSymbol = entry.getValue();
        int buildChannelIndex = buildNode.getOutputSymbols().indexOf(buildSymbol);
        verify(buildChannelIndex >= 0);
        return buildChannelIndex;
    }));
    Map<DynamicFilterId, Type> filterBuildTypes = buildChannels.entrySet().stream().collect(toImmutableMap(Map.Entry::getKey, entry -> buildSourceTypes.get(entry.getValue())));
    return new LocalDynamicFilterConsumer(buildChannels, filterBuildTypes, partitionCount);
}
Also used : ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ImmutableMap(com.google.common.collect.ImmutableMap) Domain(io.trino.spi.predicate.Domain) Type(io.trino.spi.type.Type) Set(java.util.Set) HashMap(java.util.HashMap) SettableFuture(com.google.common.util.concurrent.SettableFuture) TupleDomain(io.trino.spi.predicate.TupleDomain) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) PlanNode(io.trino.sql.planner.plan.PlanNode) ArrayList(java.util.ArrayList) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) Consumer(java.util.function.Consumer) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Verify.verify(com.google.common.base.Verify.verify) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Function.identity(java.util.function.Function.identity) JoinNode(io.trino.sql.planner.plan.JoinNode) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Type(io.trino.spi.type.Type) PlanNode(io.trino.sql.planner.plan.PlanNode) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Map(java.util.Map) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId)

Example 74 with DynamicFilterId

use of io.trino.sql.planner.plan.DynamicFilterId in project trino by trinodb.

the class TestDynamicFilterSourceOperator method testCollectWithRealNaN.

@Test
public void testCollectWithRealNaN() {
    BlockBuilder input = REAL.createBlockBuilder(null, 10);
    REAL.writeLong(input, floatToRawIntBits(42.0f));
    REAL.writeLong(input, floatToRawIntBits(Float.NaN));
    OperatorFactory operatorFactory = createOperatorFactory(channel(0, REAL));
    verifyPassthrough(createOperator(operatorFactory), ImmutableList.of(REAL), new Page(input.build()));
    operatorFactory.noMoreOperators();
    assertEquals(partitions.build(), ImmutableList.of(TupleDomain.withColumnDomains(ImmutableMap.of(new DynamicFilterId("0"), Domain.multipleValues(REAL, ImmutableList.of((long) floatToRawIntBits(42.0f)))))));
}
Also used : Page(io.trino.spi.Page) BlockBuilder(io.trino.spi.block.BlockBuilder) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test)

Example 75 with DynamicFilterId

use of io.trino.sql.planner.plan.DynamicFilterId in project trino by trinodb.

the class TestDynamicFilterSourceOperator method testCollectMultipleLargePages.

@Test
public void testCollectMultipleLargePages() {
    int maxDistinctValues = 100;
    Page page1 = new Page(createLongSequenceBlock(50, 151));
    Page page2 = new Page(createLongSequenceBlock(0, 101));
    Page page3 = new Page(createLongSequenceBlock(100, 201));
    assertDynamicFilters(maxDistinctValues, ImmutableList.of(BIGINT), ImmutableList.of(page1, page2, page3), ImmutableList.of(TupleDomain.withColumnDomains(ImmutableMap.of(new DynamicFilterId("0"), Domain.create(ValueSet.ofRanges(range(BIGINT, 0L, true, 200L, true)), false)))));
}
Also used : Page(io.trino.spi.Page) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test)

Aggregations

DynamicFilterId (io.trino.sql.planner.plan.DynamicFilterId)85 Test (org.testng.annotations.Test)73 PlanNode (io.trino.sql.planner.plan.PlanNode)32 BasePlanTest (io.trino.sql.planner.assertions.BasePlanTest)31 Symbol (io.trino.sql.planner.Symbol)29 TupleDomain (io.trino.spi.predicate.TupleDomain)26 DynamicFilter (io.trino.spi.connector.DynamicFilter)24 ColumnHandle (io.trino.spi.connector.ColumnHandle)21 TestingColumnHandle (io.trino.spi.connector.TestingColumnHandle)20 JoinNode (io.trino.sql.planner.plan.JoinNode)19 Domain (io.trino.spi.predicate.Domain)18 QueryId (io.trino.spi.QueryId)17 StageId (io.trino.execution.StageId)16 TaskId (io.trino.execution.TaskId)15 Page (io.trino.spi.Page)15 Map (java.util.Map)15 ImmutableMap (com.google.common.collect.ImmutableMap)14 Expression (io.trino.sql.tree.Expression)13 VerifyException (com.google.common.base.VerifyException)11 SymbolAllocator (io.trino.sql.planner.SymbolAllocator)11