use of io.trino.sql.planner.plan.CorrelatedJoinNode.Type.RIGHT in project trino by trinodb.
the class TestTransformUncorrelatedSubqueryToJoin method testRewriteRightCorrelatedJoin.
@Test
public void testRewriteRightCorrelatedJoin() {
tester().assertThat(new TransformUncorrelatedSubqueryToJoin()).on(p -> {
Symbol a = p.symbol("a");
Symbol b = p.symbol("b");
return p.correlatedJoin(emptyList(), p.values(a), RIGHT, TRUE_LITERAL, p.values(b));
}).matches(join(JoinNode.Type.INNER, ImmutableList.of(), Optional.empty(), values("a"), values("b")));
tester().assertThat(new TransformUncorrelatedSubqueryToJoin()).on(p -> {
Symbol a = p.symbol("a");
Symbol b = p.symbol("b");
return p.correlatedJoin(emptyList(), p.values(a), RIGHT, new ComparisonExpression(GREATER_THAN, b.toSymbolReference(), a.toSymbolReference()), p.values(b));
}).matches(project(ImmutableMap.of("a", new ExpressionMatcher("if(b > a, a, null)"), "b", new ExpressionMatcher("b")), join(JoinNode.Type.INNER, ImmutableList.of(), Optional.empty(), values("a"), values("b"))));
}
use of io.trino.sql.planner.plan.CorrelatedJoinNode.Type.RIGHT in project trino by trinodb.
the class TestPruneCorrelatedJoinColumns method testRemoveUnusedCorrelatedJoinNode.
@Test
public void testRemoveUnusedCorrelatedJoinNode() {
// retain input of INNER join
tester().assertThat(new PruneCorrelatedJoinColumns()).on(p -> {
Symbol a = p.symbol("a");
Symbol correlationSymbol = p.symbol("correlation_symbol");
Symbol b = p.symbol("b");
return p.project(Assignments.identity(a), p.correlatedJoin(ImmutableList.of(correlationSymbol), p.values(a, correlationSymbol), p.values(1, b)));
}).matches(project(ImmutableMap.of("a", PlanMatchPattern.expression("a")), values("a", "correlationSymbol")));
// retain input of LEFT join
tester().assertThat(new PruneCorrelatedJoinColumns()).on(p -> {
Symbol a = p.symbol("a");
Symbol correlationSymbol = p.symbol("correlation_symbol");
Symbol b = p.symbol("b");
return p.project(Assignments.identity(a), p.correlatedJoin(ImmutableList.of(correlationSymbol), p.values(a, correlationSymbol), LEFT, new ComparisonExpression(GREATER_THAN, b.toSymbolReference(), correlationSymbol.toSymbolReference()), p.values(1, b)));
}).matches(project(ImmutableMap.of("a", PlanMatchPattern.expression("a")), values("a", "correlationSymbol")));
// retain subquery of INNER join
tester().assertThat(new PruneCorrelatedJoinColumns()).on(p -> {
Symbol a = p.symbol("a");
Symbol b = p.symbol("b");
return p.project(Assignments.identity(b), p.correlatedJoin(ImmutableList.of(), p.values(1, a), p.values(b)));
}).matches(project(ImmutableMap.of("b", PlanMatchPattern.expression("b")), values("b")));
// retain subquery of RIGHT join
tester().assertThat(new PruneCorrelatedJoinColumns()).on(p -> {
Symbol a = p.symbol("a");
Symbol b = p.symbol("b");
return p.project(Assignments.identity(b), p.correlatedJoin(ImmutableList.of(), p.values(1, a), RIGHT, new ComparisonExpression(GREATER_THAN, b.toSymbolReference(), a.toSymbolReference()), p.values(b)));
}).matches(project(ImmutableMap.of("b", PlanMatchPattern.expression("b")), values("b")));
}
Aggregations