use of io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode in project trino by trinodb.
the class TestJoinEnumerator method testDoesNotCreateJoinWhenPartitionedOnCrossJoin.
@Test
public void testDoesNotCreateJoinWhenPartitionedOnCrossJoin() {
PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
PlanBuilder p = new PlanBuilder(idAllocator, queryRunner.getMetadata(), queryRunner.getDefaultSession());
Symbol a1 = p.symbol("A1");
Symbol b1 = p.symbol("B1");
MultiJoinNode multiJoinNode = new MultiJoinNode(new LinkedHashSet<>(ImmutableList.of(p.values(a1), p.values(b1))), TRUE_LITERAL, ImmutableList.of(a1, b1), false);
JoinEnumerator joinEnumerator = new JoinEnumerator(queryRunner.getMetadata(), new CostComparator(1, 1, 1), multiJoinNode.getFilter(), createContext());
JoinEnumerationResult actual = joinEnumerator.createJoinAccordingToPartitioning(multiJoinNode.getSources(), multiJoinNode.getOutputSymbols(), ImmutableSet.of(0));
assertFalse(actual.getPlanNode().isPresent());
assertEquals(actual.getCost(), PlanCostEstimate.infinite());
}
use of io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode in project trino by trinodb.
the class TestJoinNodeFlattener method testConvertsBushyTrees.
@Test
public void testConvertsBushyTrees() {
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 joinNode = p.join(INNER, p.join(INNER, p.join(INNER, valuesA, valuesB, ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1), ImmutableList.of(b1), Optional.empty()), valuesC, ImmutableList.of(equiJoinClause(a1, c1)), ImmutableList.of(a1, b1), ImmutableList.of(c1), Optional.empty()), p.join(INNER, valuesD, valuesE, ImmutableList.of(equiJoinClause(d1, e1), equiJoinClause(d2, e2)), ImmutableList.of(d1, d2), ImmutableList.of(e1, e2), Optional.empty()), ImmutableList.of(equiJoinClause(b1, e1)), ImmutableList.of(a1, b1, c1), ImmutableList.of(d1, d2, e1, e2), Optional.empty());
MultiJoinNode expected = MultiJoinNode.builder().setSources(valuesA, valuesB, valuesC, valuesD, valuesE).setFilter(and(createEqualsExpression(a1, b1), createEqualsExpression(a1, c1), createEqualsExpression(d1, e1), createEqualsExpression(d2, e2), createEqualsExpression(b1, e1))).setOutputSymbols(a1, b1, c1, d1, d2, e1, e2).build();
assertEquals(toMultiJoinNode(queryRunner.getPlannerContext(), joinNode, noLookup(), planNodeIdAllocator, 5, false, testSessionBuilder().build(), createTestingTypeAnalyzer(queryRunner.getPlannerContext()), p.getTypes()), expected);
}
use of io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode in project trino by trinodb.
the class TestJoinNodeFlattener method testRetainsOutputSymbols.
@Test
public void testRetainsOutputSymbols() {
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);
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.empty()), ImmutableList.of(equiJoinClause(a1, b1)), ImmutableList.of(a1), ImmutableList.of(b1), Optional.empty());
MultiJoinNode expected = MultiJoinNode.builder().setSources(valuesA, valuesB, valuesC).setFilter(and(createEqualsExpression(b1, c1), createEqualsExpression(a1, b1))).setOutputSymbols(a1, b1).build();
assertEquals(toMultiJoinNode(queryRunner.getPlannerContext(), joinNode, noLookup(), planNodeIdAllocator, DEFAULT_JOIN_LIMIT, false, testSessionBuilder().build(), createTestingTypeAnalyzer(queryRunner.getPlannerContext()), p.getTypes()), expected);
}
use of io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode 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);
}
use of io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode 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"));
}
Aggregations