Search in sources :

Example 96 with PlanNode

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

the class TestRemoveUnsupportedDynamicFilters method removeUnsupportedDynamicFilters.

private PlanNode removeUnsupportedDynamicFilters(PlanNode root) {
    return getQueryRunner().inTransaction(session -> {
        // metadata.getCatalogHandle() registers the catalog for the transaction
        session.getCatalog().ifPresent(catalog -> metadata.getCatalogHandle(session, catalog));
        PlanNode rewrittenPlan = new RemoveUnsupportedDynamicFilters(plannerContext).optimize(root, session, builder.getTypes(), new SymbolAllocator(), new PlanNodeIdAllocator(), WarningCollector.NOOP);
        new DynamicFiltersChecker().validate(rewrittenPlan, session, plannerContext, createTestingTypeAnalyzer(plannerContext), builder.getTypes(), WarningCollector.NOOP);
        return rewrittenPlan;
    });
}
Also used : SymbolAllocator(io.trino.sql.planner.SymbolAllocator) PlanNode(io.trino.sql.planner.plan.PlanNode) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) DynamicFiltersChecker(io.trino.sql.planner.sanity.DynamicFiltersChecker) RemoveUnsupportedDynamicFilters(io.trino.sql.planner.iterative.rule.RemoveUnsupportedDynamicFilters)

Example 97 with PlanNode

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

the class TestRemoveUnsupportedDynamicFilters 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(), ImmutableList.of(), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of()));
    assertPlan(removeUnsupportedDynamicFilters(root), output(join(INNER, ImmutableList.of(equiJoinClause("ORDERS_OK", "LINEITEM_OK")), ImmutableMap.of(), tableScan("orders", ImmutableMap.of("ORDERS_OK", "orderkey")), filter(expression("LINEITEM_OK > 0"), tableScan("lineitem", ImmutableMap.of("LINEITEM_OK", "orderkey"))))));
}
Also used : PlanNode(io.trino.sql.planner.plan.PlanNode) SpatialJoinNode(io.trino.sql.planner.plan.SpatialJoinNode) 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 98 with PlanNode

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

the class TestRemoveUnsupportedDynamicFilters method testRemoveUnsupportedCast.

@Test
public void testRemoveUnsupportedCast() {
    // Use lineitem with DOUBLE orderkey to simulate the case of implicit casts
    // Dynamic filter is removed because there isn't an injective mapping from bigint -> double
    Symbol lineitemDoubleOrderKeySymbol = builder.symbol("LINEITEM_DOUBLE_OK", DOUBLE);
    PlanNode root = builder.output(ImmutableList.of(), ImmutableList.of(), builder.join(INNER, builder.filter(createDynamicFilterExpression(TEST_SESSION, metadata, new DynamicFilterId("DF"), BIGINT, expression("CAST(LINEITEM_DOUBLE_OK AS BIGINT)")), builder.tableScan(lineitemTableHandle, ImmutableList.of(lineitemDoubleOrderKeySymbol), ImmutableMap.of(lineitemDoubleOrderKeySymbol, new TpchColumnHandle("orderkey", DOUBLE)))), ordersTableScanNode, ImmutableList.of(new JoinNode.EquiJoinClause(lineitemDoubleOrderKeySymbol, ordersOrderKeySymbol)), ImmutableList.of(lineitemDoubleOrderKeySymbol), ImmutableList.of(ordersOrderKeySymbol), Optional.empty(), Optional.empty(), Optional.empty(), ImmutableMap.of(new DynamicFilterId("DF"), ordersOrderKeySymbol)));
    assertPlan(removeUnsupportedDynamicFilters(root), output(join(INNER, ImmutableList.of(equiJoinClause("LINEITEM_DOUBLE_OK", "ORDERS_OK")), ImmutableMap.of(), tableScan("lineitem", ImmutableMap.of("LINEITEM_DOUBLE_OK", "orderkey")), tableScan("orders", ImmutableMap.of("ORDERS_OK", "orderkey")))));
}
Also used : PlanNode(io.trino.sql.planner.plan.PlanNode) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) Symbol(io.trino.sql.planner.Symbol) SpatialJoinNode(io.trino.sql.planner.plan.SpatialJoinNode) 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 99 with PlanNode

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

the class TestRemoveUnsupportedDynamicFilters method testUnconsumedDynamicFilterInSemiJoin.

@Test
public void testUnconsumedDynamicFilterInSemiJoin() {
    PlanNode root = builder.semiJoin(builder.filter(expression("ORDERS_OK > 0"), ordersTableScanNode), lineitemTableScanNode, ordersOrderKeySymbol, lineitemOrderKeySymbol, new Symbol("SEMIJOIN_OUTPUT"), Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(new DynamicFilterId("DF")));
    assertPlan(removeUnsupportedDynamicFilters(root), semiJoin("ORDERS_OK", "LINEITEM_OK", "SEMIJOIN_OUTPUT", false, filter(expression("ORDERS_OK > 0"), tableScan("orders", ImmutableMap.of("ORDERS_OK", "orderkey"))), tableScan("lineitem", ImmutableMap.of("LINEITEM_OK", "orderkey"))));
}
Also used : PlanNode(io.trino.sql.planner.plan.PlanNode) 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 100 with PlanNode

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

the class RuleAssert method applyRule.

private RuleApplication applyRule() {
    SymbolAllocator symbolAllocator = new SymbolAllocator(types.allTypes());
    Memo memo = new Memo(idAllocator, plan);
    Lookup lookup = Lookup.from(planNode -> Stream.of(memo.resolve(planNode)));
    PlanNode memoRoot = memo.getNode(memo.getRootGroup());
    return inTransaction(session -> applyRule(rule, memoRoot, ruleContext(statsCalculator, costCalculator, symbolAllocator, memo, lookup, session)));
}
Also used : SymbolAllocator(io.trino.sql.planner.SymbolAllocator) PlanNode(io.trino.sql.planner.plan.PlanNode) Lookup(io.trino.sql.planner.iterative.Lookup) Memo(io.trino.sql.planner.iterative.Memo)

Aggregations

PlanNode (io.trino.sql.planner.plan.PlanNode)235 Test (org.testng.annotations.Test)90 Symbol (io.trino.sql.planner.Symbol)83 Expression (io.trino.sql.tree.Expression)62 ImmutableList (com.google.common.collect.ImmutableList)52 JoinNode (io.trino.sql.planner.plan.JoinNode)52 ProjectNode (io.trino.sql.planner.plan.ProjectNode)51 List (java.util.List)43 Session (io.trino.Session)41 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)39 Map (java.util.Map)37 Optional (java.util.Optional)37 AggregationNode (io.trino.sql.planner.plan.AggregationNode)35 BasePlanTest (io.trino.sql.planner.assertions.BasePlanTest)34 Assignments (io.trino.sql.planner.plan.Assignments)33 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)32 Objects.requireNonNull (java.util.Objects.requireNonNull)31 ImmutableMap (com.google.common.collect.ImmutableMap)29 ImmutableSet (com.google.common.collect.ImmutableSet)29 Set (java.util.Set)29