use of io.trino.sql.planner.plan.Assignments in project trino by trinodb.
the class TestPushProjectionThroughExchange method testDoNotSkipIdentityProjectionIfOutputAbsent.
@Test
public void testDoNotSkipIdentityProjectionIfOutputAbsent() {
// In the following example, the Projection over Exchange has got an identity assignment (a -> a).
// The Projection is pushed down to Exchange's source, and the identity assignment is translated into
// a0 -> a. Input symbol 'a' is not used in the Exchange for partitioning, ordering or as a hash symbol.
// It is just passed to output.
// When all the assignments from the parent Projection are added to the pushed-down Projection,
// the translated assignment is added too, so that the input symbol 'a' can be passed to the Exchange's output.
tester().assertThat(new PushProjectionThroughExchange()).on(p -> {
Symbol a = p.symbol("a");
Symbol aTimes5 = p.symbol("a_times_5");
return p.project(Assignments.of(aTimes5, new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.MULTIPLY, new SymbolReference("a"), new LongLiteral("5")), a, a.toSymbolReference()), p.exchange(e -> e.addSource(p.values(a)).addInputsSet(a).singleDistributionPartitioningScheme(a)));
}).matches(exchange(strictProject(ImmutableMap.of("a_0", expression("a"), "a_times_5", expression("a * 5")), values(ImmutableList.of("a")))));
// In the following example, the Projection over Exchange has got an identity assignment (b -> b).
// The Projection is pushed down to Exchange's source, and the identity assignment is translated into
// a0 -> a. Input symbol 'a' is not used in the Exchange for partitioning, ordering or as a hash symbol.
// It is just passed to output.
// When all the assignments from the parent Projection are added to the pushed-down Projection,
// the translated assignment is added too, so that the input symbol 'a' can be passed to the Exchange's output.
tester().assertThat(new PushProjectionThroughExchange()).on(p -> {
Symbol a = p.symbol("a");
Symbol bTimes5 = p.symbol("b_times_5");
Symbol b = p.symbol("b");
return p.project(Assignments.of(bTimes5, new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.MULTIPLY, new SymbolReference("b"), new LongLiteral("5")), b, b.toSymbolReference()), p.exchange(e -> e.addSource(p.values(a)).addInputsSet(a).singleDistributionPartitioningScheme(b)));
}).matches(exchange(strictProject(ImmutableMap.of("a_0", expression("a"), "a_times_5", expression("a * 5")), values(ImmutableList.of("a")))));
}
Aggregations