Search in sources :

Example 21 with PlanNodeIdAllocator

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

the class TestJoinNodeFlattener method testDoesNotAllowOuterJoin.

@Test
public void testDoesNotAllowOuterJoin() {
    PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
    PlanBuilder p = planBuilder(planNodeIdAllocator);
    Symbol a1 = p.symbol("A1");
    Symbol b1 = p.symbol("B1");
    JoinNode outerJoin = p.join(FULL, p.values(a1), p.values(b1), ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1), ImmutableList.of(b1), Optional.empty());
    assertThatThrownBy(() -> toMultiJoinNode(queryRunner.getPlannerContext(), outerJoin, noLookup(), planNodeIdAllocator, DEFAULT_JOIN_LIMIT, false, testSessionBuilder().build(), createTestingTypeAnalyzer(queryRunner.getPlannerContext()), p.getTypes())).isInstanceOf(IllegalStateException.class).hasMessageMatching("join type must be.*");
}
Also used : 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) Test(org.testng.annotations.Test)

Example 22 with PlanNodeIdAllocator

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

the class TestJoinNodeFlattener method testCombinesCriteriaAndFilters.

@Test
public void testCombinesCriteriaAndFilters() {
    PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
    PlanBuilder p = planBuilder(planNodeIdAllocator);
    Symbol a1 = p.symbol("A1");
    Symbol b1 = p.symbol("B1");
    Symbol b2 = p.symbol("B2");
    Symbol c1 = p.symbol("C1");
    Symbol c2 = p.symbol("C2");
    ValuesNode valuesA = p.values(a1);
    ValuesNode valuesB = p.values(b1, b2);
    ValuesNode valuesC = p.values(c1, c2);
    Expression bcFilter = and(new ComparisonExpression(GREATER_THAN, c2.toSymbolReference(), new LongLiteral("0")), new ComparisonExpression(NOT_EQUAL, c2.toSymbolReference(), new LongLiteral("7")), new ComparisonExpression(GREATER_THAN, b2.toSymbolReference(), c2.toSymbolReference()));
    ComparisonExpression abcFilter = new ComparisonExpression(LESS_THAN, new ArithmeticBinaryExpression(ADD, a1.toSymbolReference(), c1.toSymbolReference()), b1.toSymbolReference());
    JoinNode joinNode = p.join(INNER, valuesA, p.join(INNER, valuesB, valuesC, ImmutableList.of(equiJoinClause(b1, c1)), ImmutableList.of(b1, b2), ImmutableList.of(c1, c2), Optional.of(bcFilter)), ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1), ImmutableList.of(b1, b2, c1, c2), Optional.of(abcFilter));
    MultiJoinNode expected = new MultiJoinNode(new LinkedHashSet<>(ImmutableList.of(valuesA, valuesB, valuesC)), and(new ComparisonExpression(EQUAL, b1.toSymbolReference(), c1.toSymbolReference()), new ComparisonExpression(EQUAL, a1.toSymbolReference(), b1.toSymbolReference()), bcFilter, abcFilter), ImmutableList.of(a1, b1, b2, c1, c2), false);
    assertEquals(toMultiJoinNode(queryRunner.getPlannerContext(), joinNode, noLookup(), planNodeIdAllocator, DEFAULT_JOIN_LIMIT, false, testSessionBuilder().build(), createTestingTypeAnalyzer(queryRunner.getPlannerContext()), p.getTypes()), expected);
}
Also used : ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) ValuesNode(io.trino.sql.planner.plan.ValuesNode) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) Expression(io.trino.sql.tree.Expression) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) LongLiteral(io.trino.sql.tree.LongLiteral) 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 23 with PlanNodeIdAllocator

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

the class TestJoinNodeFlattener method testDoesNotPushStraddlingProjection.

@Test
public void testDoesNotPushStraddlingProjection() {
    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 ArithmeticBinaryExpression(SUBTRACT, a.toSymbolReference(), b.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(), createEqualsExpression(d, c));
    assertFalse(actual.isPushedProjectionThroughJoin());
    List<PlanNode> actualSources = ImmutableList.copyOf(actual.getSources());
    assertPlan(p.getTypes(), actualSources.get(0), node(ProjectNode.class, node(JoinNode.class, values("a"), values("b"))).withNumberOfOutputColumns(1));
    assertPlan(p.getTypes(), actualSources.get(1), values("c"));
}
Also used : ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) 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) 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 24 with PlanNodeIdAllocator

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

the class TestJoinNodeFlattener method testMoreThanJoinLimit.

@Test
public void testMoreThanJoinLimit() {
    PlanNodeIdAllocator planNodeIdAllocator = new PlanNodeIdAllocator();
    PlanBuilder p = planBuilder(planNodeIdAllocator);
    Symbol a1 = p.symbol("A1");
    Symbol b1 = p.symbol("B1");
    Symbol c1 = p.symbol("C1");
    Symbol d1 = p.symbol("D1");
    Symbol d2 = p.symbol("D2");
    Symbol e1 = p.symbol("E1");
    Symbol e2 = p.symbol("E2");
    ValuesNode valuesA = p.values(a1);
    ValuesNode valuesB = p.values(b1);
    ValuesNode valuesC = p.values(c1);
    ValuesNode valuesD = p.values(d1, d2);
    ValuesNode valuesE = p.values(e1, e2);
    JoinNode join1 = p.join(INNER, valuesA, valuesB, ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1), ImmutableList.of(b1), Optional.empty());
    JoinNode join2 = p.join(INNER, valuesD, valuesE, ImmutableList.of(equiJoinClause(d1, e1), equiJoinClause(d2, e2)), ImmutableList.of(d1, d2), ImmutableList.of(e1, e2), Optional.empty());
    JoinNode joinNode = p.join(INNER, p.join(INNER, join1, valuesC, ImmutableList.of(equiJoinClause(a1, c1)), ImmutableList.of(a1, b1), ImmutableList.of(c1), Optional.empty()), join2, ImmutableList.of(equiJoinClause(b1, e1)), ImmutableList.of(a1, b1, c1), ImmutableList.of(d1, d2, e1, e2), Optional.empty());
    MultiJoinNode expected = MultiJoinNode.builder().setSources(join1, join2, valuesC).setFilter(and(createEqualsExpression(a1, c1), createEqualsExpression(b1, e1))).setOutputSymbols(a1, b1, c1, d1, d2, e1, e2).build();
    assertEquals(toMultiJoinNode(queryRunner.getPlannerContext(), joinNode, noLookup(), planNodeIdAllocator, 2, 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 25 with PlanNodeIdAllocator

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

the class TestEliminateCrossJoins method testJoinOrderWithMultipleEdgesBetweenNodes.

@Test
public void testJoinOrderWithMultipleEdgesBetweenNodes() {
    Session session = testSessionBuilder().build();
    PlanNode plan = joinNode(joinNode(values("a"), values("b1", "b2")), values("c1", "c2"), "a", "c1", "b1", "c1", "b2", "c2");
    JoinGraph joinGraph = JoinGraph.buildFrom(tester().getPlannerContext(), plan, noLookup(), new PlanNodeIdAllocator(), session, createTestingTypeAnalyzer(tester().getPlannerContext()), TypeProvider.empty());
    assertEquals(getJoinOrder(joinGraph), ImmutableList.of(0, 2, 1));
}
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)

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