Search in sources :

Example 36 with DynamicFilterId

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

the class TestDynamicFiltersChecker method testUnmatchedDynamicFilterInSemiJoin.

@Test
public void testUnmatchedDynamicFilterInSemiJoin() {
    PlanNode root = builder.output(ImmutableList.of(), ImmutableList.of(), builder.semiJoin(builder.filter(combineConjuncts(metadata, expression("ORDERS_OK > 0"), createDynamicFilterExpression(TEST_SESSION, metadata, new DynamicFilterId("DF"), BIGINT, ordersOrderKeySymbol.toSymbolReference())), ordersTableScanNode), lineitemTableScanNode, ordersOrderKeySymbol, lineitemOrderKeySymbol, new Symbol("SEMIJOIN_OUTPUT"), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()));
    assertThatThrownBy(() -> validatePlan(root)).isInstanceOf(VerifyException.class).hasMessage("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) Symbol(io.trino.sql.planner.Symbol) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Example 37 with DynamicFilterId

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

the class TestDynamicFiltersChecker method testUnmatchedDynamicFilter.

@Test
public void testUnmatchedDynamicFilter() {
    PlanNode root = builder.output(ImmutableList.of(), ImmutableList.of(), builder.join(INNER, ordersTableScanNode, builder.filter(combineConjuncts(metadata, expression("LINEITEM_OK > 0"), 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 38 with DynamicFilterId

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

the class TestDynamicFiltersChecker method testUnsupportedCastExpression.

@Test
public void testUnsupportedCastExpression() {
    PlanNode root = builder.output(ImmutableList.of(), ImmutableList.of(), builder.join(INNER, builder.filter(createDynamicFilterExpression(TEST_SESSION, metadata, new DynamicFilterId("DF"), BIGINT, expression("CAST(CAST(LINEITEM_OK AS INT) AS BIGINT)")), 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("The expression CAST\\(\"LINEITEM_OK\" AS INT\\) within in a CAST in dynamic filter must be a 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 39 with DynamicFilterId

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

the class TestDynamicFiltersCollector method testDynamicFiltersCollector.

@Test
public void testDynamicFiltersCollector() {
    DynamicFilterId filter = new DynamicFilterId("filter");
    DynamicFiltersCollector collector = new DynamicFiltersCollector(() -> {
    });
    VersionedDynamicFilterDomains domains = collector.acknowledgeAndGetNewDomains(INITIAL_DYNAMIC_FILTERS_VERSION);
    // there should be no domains initially
    assertEquals(domains.getVersion(), INITIAL_DYNAMIC_FILTERS_VERSION);
    assertEquals(domains.getDynamicFilterDomains(), ImmutableMap.of());
    Domain initialDomain = multipleValues(BIGINT, ImmutableList.of(1L, 2L, 3L));
    collector.updateDomains(ImmutableMap.of(filter, initialDomain));
    domains = collector.acknowledgeAndGetNewDomains(INITIAL_DYNAMIC_FILTERS_VERSION);
    assertEquals(domains.getVersion(), 1L);
    assertEquals(domains.getDynamicFilterDomains(), ImmutableMap.of(filter, initialDomain));
    // make sure domains are still available when requested again with old version
    domains = collector.acknowledgeAndGetNewDomains(INITIAL_DYNAMIC_FILTERS_VERSION);
    assertEquals(domains.getVersion(), 1L);
    assertEquals(domains.getDynamicFilterDomains(), ImmutableMap.of(filter, initialDomain));
    // make sure domains are intersected
    collector.updateDomains(ImmutableMap.of(filter, multipleValues(BIGINT, ImmutableList.of(2L))));
    collector.updateDomains(ImmutableMap.of(filter, multipleValues(BIGINT, ImmutableList.of(3L, 4L))));
    domains = collector.acknowledgeAndGetNewDomains(1L);
    assertEquals(domains.getVersion(), 3L);
    assertEquals(domains.getDynamicFilterDomains(), ImmutableMap.of(filter, Domain.none(BIGINT)));
    // make sure old domains are removed
    DynamicFilterId filter2 = new DynamicFilterId("filter2");
    collector.updateDomains(ImmutableMap.of(filter2, singleValue(BIGINT, 1L)));
    domains = collector.acknowledgeAndGetNewDomains(3L);
    assertEquals(domains.getVersion(), 4L);
    assertEquals(domains.getDynamicFilterDomains(), ImmutableMap.of(filter2, singleValue(BIGINT, 1L)));
}
Also used : Domain(io.trino.spi.predicate.Domain) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) VersionedDynamicFilterDomains(io.trino.execution.DynamicFiltersCollector.VersionedDynamicFilterDomains) Test(org.testng.annotations.Test)

Example 40 with DynamicFilterId

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

the class TestUnaliasSymbolReferences method testDynamicFilterIdUnAliased.

@Test
public void testDynamicFilterIdUnAliased() {
    String probeTable = "supplier";
    String buildTable = "nation";
    assertOptimizedPlan(new UnaliasSymbolReferences(getQueryRunner().getMetadata()), (p, session, metadata) -> {
        ColumnHandle column = new TpchColumnHandle("nationkey", BIGINT);
        Symbol buildColumnSymbol = p.symbol("nationkey");
        Symbol buildAlias1 = p.symbol("buildAlias1");
        Symbol buildAlias2 = p.symbol("buildAlias2");
        Symbol probeColumn1 = p.symbol("s_nationkey");
        Symbol probeColumn2 = p.symbol("s_suppkey");
        DynamicFilterId dynamicFilterId1 = new DynamicFilterId("df1");
        DynamicFilterId dynamicFilterId2 = new DynamicFilterId("df2");
        return p.join(INNER, p.filter(// additional filter to test recursive call
        TRUE_LITERAL, p.filter(ExpressionUtils.and(dynamicFilterExpression(metadata, session, probeColumn1, dynamicFilterId1), dynamicFilterExpression(metadata, session, probeColumn2, dynamicFilterId2)), p.tableScan(tableHandle(session, probeTable), ImmutableList.of(probeColumn1, probeColumn2), ImmutableMap.of(probeColumn1, new TpchColumnHandle("nationkey", BIGINT), probeColumn2, new TpchColumnHandle("suppkey", BIGINT))))), p.project(Assignments.of(buildAlias1, buildColumnSymbol.toSymbolReference(), buildAlias2, buildColumnSymbol.toSymbolReference()), p.tableScan(tableHandle(session, buildTable), ImmutableList.of(buildColumnSymbol), ImmutableMap.of(buildColumnSymbol, column))), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(buildAlias1, buildAlias2), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(dynamicFilterId1, buildAlias1, dynamicFilterId2, buildAlias2));
    }, join(INNER, ImmutableList.of(), ImmutableMap.of("probeColumn1", "column", "probeColumn2", "column"), filter(TRUE_LITERAL, filter(TRUE_LITERAL, tableScan(probeTable, ImmutableMap.of("probeColumn1", "suppkey", "probeColumn2", "nationkey")))), project(tableScan(buildTable, ImmutableMap.of("column", "nationkey")))));
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) Symbol(io.trino.sql.planner.Symbol) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

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