Search in sources :

Example 61 with Assignments

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")))));
}
Also used : Symbol(io.trino.sql.planner.Symbol) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Assignments(io.trino.sql.planner.plan.Assignments) Test(org.testng.annotations.Test) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) OrderingScheme(io.trino.sql.planner.OrderingScheme) FIRST(io.trino.sql.tree.SortItem.NullOrdering.FIRST) SortOrder(io.trino.spi.connector.SortOrder) PlanMatchPattern.strictProject(io.trino.sql.planner.assertions.PlanMatchPattern.strictProject) GATHER(io.trino.sql.planner.plan.ExchangeNode.Type.GATHER) ImmutableList(com.google.common.collect.ImmutableList) PlanMatchPattern.project(io.trino.sql.planner.assertions.PlanMatchPattern.project) SymbolReference(io.trino.sql.tree.SymbolReference) LongLiteral(io.trino.sql.tree.LongLiteral) PlanMatchPattern.exchange(io.trino.sql.planner.assertions.PlanMatchPattern.exchange) PlanMatchPattern.sort(io.trino.sql.planner.assertions.PlanMatchPattern.sort) REMOTE(io.trino.sql.planner.plan.ExchangeNode.Scope.REMOTE) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) ASCENDING(io.trino.sql.tree.SortItem.Ordering.ASCENDING) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) LongLiteral(io.trino.sql.tree.LongLiteral) Symbol(io.trino.sql.planner.Symbol) SymbolReference(io.trino.sql.tree.SymbolReference) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Test(org.testng.annotations.Test)

Aggregations

Assignments (io.trino.sql.planner.plan.Assignments)61 ProjectNode (io.trino.sql.planner.plan.ProjectNode)50 Symbol (io.trino.sql.planner.Symbol)39 Expression (io.trino.sql.tree.Expression)39 ImmutableList (com.google.common.collect.ImmutableList)36 Map (java.util.Map)33 PlanNode (io.trino.sql.planner.plan.PlanNode)26 SymbolReference (io.trino.sql.tree.SymbolReference)26 Captures (io.trino.matching.Captures)23 Pattern (io.trino.matching.Pattern)23 Rule (io.trino.sql.planner.iterative.Rule)23 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)21 Objects.requireNonNull (java.util.Objects.requireNonNull)21 Set (java.util.Set)21 Capture (io.trino.matching.Capture)20 Capture.newCapture (io.trino.matching.Capture.newCapture)20 TypeAnalyzer (io.trino.sql.planner.TypeAnalyzer)19 Patterns.source (io.trino.sql.planner.plan.Patterns.source)19 SubscriptExpression (io.trino.sql.tree.SubscriptExpression)18 ImmutableMap (com.google.common.collect.ImmutableMap)17