Search in sources :

Example 11 with PlanNodeIdAllocator

use of io.trino.sql.planner.PlanNodeIdAllocator in project trino by trinodb.

the class TestJoinNodeFlattener method testDoesNotConvertNestedOuterJoins.

@Test
public void testDoesNotConvertNestedOuterJoins() {
    PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
    PlanBuilder p = planBuilder(planNodeIdAllocator);
    Symbol a1 = p.symbol("A1");
    Symbol b1 = p.symbol("B1");
    Symbol c1 = p.symbol("C1");
    JoinNode leftJoin = p.join(LEFT, p.values(a1), p.values(b1), ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1), ImmutableList.of(b1), Optional.empty());
    ValuesNode valuesC = p.values(c1);
    JoinNode joinNode = p.join(INNER, leftJoin, valuesC, ImmutableList.of(equiJoinClause(a1, c1)), ImmutableList.of(a1, b1), ImmutableList.of(c1), Optional.empty());
    MultiJoinNode expected = MultiJoinNode.builder().setSources(leftJoin, valuesC).setFilter(createEqualsExpression(a1, c1)).setOutputSymbols(a1, b1, c1).build();
    assertEquals(toMultiJoinNode(queryRunner.getPlannerContext(), joinNode, noLookup(), planNodeIdAllocator, DEFAULT_JOIN_LIMIT, false, testSessionBuilder().build(), createTestingTypeAnalyzer(queryRunner.getPlannerContext()), p.getTypes()), expected);
}
Also used : ValuesNode(io.trino.sql.planner.plan.ValuesNode) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Symbol(io.trino.sql.planner.Symbol) JoinNode(io.trino.sql.planner.plan.JoinNode) MultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) MultiJoinNode.toMultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) MultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) MultiJoinNode.toMultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) Test(org.testng.annotations.Test)

Example 12 with PlanNodeIdAllocator

use of io.trino.sql.planner.PlanNodeIdAllocator in project trino by trinodb.

the class TestJoinNodeFlattener method testPushesProjectionsThroughJoin.

@Test
public void testPushesProjectionsThroughJoin() {
    PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
    PlanBuilder p = planBuilder(planNodeIdAllocator);
    Symbol a = p.symbol("A");
    Symbol b = p.symbol("B");
    Symbol c = p.symbol("C");
    Symbol d = p.symbol("D");
    ValuesNode valuesA = p.values(a);
    ValuesNode valuesB = p.values(b);
    ValuesNode valuesC = p.values(c);
    JoinNode joinNode = p.join(INNER, p.project(Assignments.of(d, new ArithmeticUnaryExpression(MINUS, a.toSymbolReference())), p.join(INNER, valuesA, valuesB, equiJoinClause(a, b))), valuesC, equiJoinClause(d, c));
    MultiJoinNode actual = toMultiJoinNode(queryRunner.getPlannerContext(), joinNode, noLookup(), planNodeIdAllocator, DEFAULT_JOIN_LIMIT, true, testSessionBuilder().build(), createTestingTypeAnalyzer(queryRunner.getPlannerContext()), p.getTypes());
    assertEquals(actual.getOutputSymbols(), ImmutableList.of(d, c));
    assertEquals(actual.getFilter(), and(createEqualsExpression(a, b), createEqualsExpression(d, c)));
    assertTrue(actual.isPushedProjectionThroughJoin());
    List<PlanNode> actualSources = ImmutableList.copyOf(actual.getSources());
    assertPlan(p.getTypes(), actualSources.get(0), node(ProjectNode.class, values("a")).withNumberOfOutputColumns(2));
    assertPlan(p.getTypes(), actualSources.get(1), node(ProjectNode.class, values("b")).withNumberOfOutputColumns(1));
    assertPlan(p.getTypes(), actualSources.get(2), values("c"));
}
Also used : ValuesNode(io.trino.sql.planner.plan.ValuesNode) PlanNode(io.trino.sql.planner.plan.PlanNode) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Symbol(io.trino.sql.planner.Symbol) JoinNode(io.trino.sql.planner.plan.JoinNode) MultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) MultiJoinNode.toMultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) MultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) MultiJoinNode.toMultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) Test(org.testng.annotations.Test)

Example 13 with PlanNodeIdAllocator

use of io.trino.sql.planner.PlanNodeIdAllocator in project trino by trinodb.

the class TestEliminateCrossJoins method testJoinOrderWithRealCrossJoin.

@Test
public void testJoinOrderWithRealCrossJoin() {
    Session session = testSessionBuilder().build();
    PlanNode leftPlan = joinNode(joinNode(values("a"), values("b")), values("c"), "a", "c", "b", "c");
    PlanNode rightPlan = joinNode(joinNode(values("x"), values("y")), values("z"), "x", "z", "y", "z");
    PlanNode plan = joinNode(leftPlan, rightPlan);
    JoinGraph joinGraph = JoinGraph.buildFrom(tester().getPlannerContext(), plan, noLookup(), new PlanNodeIdAllocator(), session, createTestingTypeAnalyzer(tester().getPlannerContext()), TypeProvider.empty());
    assertEquals(getJoinOrder(joinGraph), ImmutableList.of(0, 2, 1, 3, 5, 4));
}
Also used : PlanNode(io.trino.sql.planner.plan.PlanNode) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Session(io.trino.Session) JoinGraph(io.trino.sql.planner.optimizations.joins.JoinGraph) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Example 14 with PlanNodeIdAllocator

use of io.trino.sql.planner.PlanNodeIdAllocator 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 15 with PlanNodeIdAllocator

use of io.trino.sql.planner.PlanNodeIdAllocator in project trino by trinodb.

the class TestUnaliasSymbolReferences method assertOptimizedPlan.

private void assertOptimizedPlan(PlanOptimizer optimizer, PlanCreator planCreator, PlanMatchPattern pattern) {
    LocalQueryRunner queryRunner = getQueryRunner();
    queryRunner.inTransaction(session -> {
        Metadata metadata = queryRunner.getMetadata();
        session.getCatalog().ifPresent(catalog -> metadata.getCatalogHandle(session, catalog));
        PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
        PlanBuilder planBuilder = new PlanBuilder(idAllocator, metadata, session);
        SymbolAllocator symbolAllocator = new SymbolAllocator();
        PlanNode plan = planCreator.create(planBuilder, session, metadata);
        PlanNode optimized = optimizer.optimize(plan, session, planBuilder.getTypes(), symbolAllocator, idAllocator, WarningCollector.NOOP);
        Plan actual = new Plan(optimized, planBuilder.getTypes(), StatsAndCosts.empty());
        PlanAssert.assertPlan(session, queryRunner.getMetadata(), queryRunner.getFunctionManager(), queryRunner.getStatsCalculator(), actual, pattern);
        return null;
    });
}
Also used : SymbolAllocator(io.trino.sql.planner.SymbolAllocator) PlanNode(io.trino.sql.planner.plan.PlanNode) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Metadata(io.trino.metadata.Metadata) Plan(io.trino.sql.planner.Plan) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) LocalQueryRunner(io.trino.testing.LocalQueryRunner)

Aggregations

PlanNodeIdAllocator (io.trino.sql.planner.PlanNodeIdAllocator)34 PlanBuilder (io.trino.sql.planner.iterative.rule.test.PlanBuilder)21 Test (org.testng.annotations.Test)21 Symbol (io.trino.sql.planner.Symbol)16 PlanNode (io.trino.sql.planner.plan.PlanNode)16 JoinNode (io.trino.sql.planner.plan.JoinNode)11 Session (io.trino.Session)9 MultiJoinNode (io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode)9 MultiJoinNode.toMultiJoinNode (io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode)8 ValuesNode (io.trino.sql.planner.plan.ValuesNode)8 BaseRuleTest (io.trino.sql.planner.iterative.rule.test.BaseRuleTest)6 JoinGraph (io.trino.sql.planner.optimizations.joins.JoinGraph)5 ArithmeticBinaryExpression (io.trino.sql.tree.ArithmeticBinaryExpression)5 SymbolAllocator (io.trino.sql.planner.SymbolAllocator)4 CatalogName (io.trino.connector.CatalogName)3 TableHandle (io.trino.metadata.TableHandle)3 TpchColumnHandle (io.trino.plugin.tpch.TpchColumnHandle)3 TpchTableHandle (io.trino.plugin.tpch.TpchTableHandle)3 LogicalPlanner (io.trino.sql.planner.LogicalPlanner)3 ProjectNode (io.trino.sql.planner.plan.ProjectNode)3