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);
}
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"));
}
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));
}
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;
});
}
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;
});
}
Aggregations