Search in sources :

Example 16 with ValuesNode

use of io.trino.sql.planner.plan.ValuesNode 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"));
}
Also used : ValuesNode(io.trino.sql.planner.plan.ValuesNode) PlanNode(io.trino.sql.planner.plan.PlanNode) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Symbol(io.trino.sql.planner.Symbol) JoinNode(io.trino.sql.planner.plan.JoinNode) MultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) MultiJoinNode.toMultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) MultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) MultiJoinNode.toMultiJoinNode(io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode) Test(org.testng.annotations.Test)

Example 17 with ValuesNode

use of io.trino.sql.planner.plan.ValuesNode in project trino by trinodb.

the class TestMergeExcept method buildNestedExcept.

private PlanNode buildNestedExcept(PlanBuilder builder, boolean sourceDistinct, boolean parentDistinct) {
    Symbol v1 = builder.symbol("v_1");
    Symbol v2 = builder.symbol("v_2");
    Symbol a = builder.symbol("a");
    Symbol b = builder.symbol("b");
    Symbol c = builder.symbol("c");
    ExceptNode child1 = builder.except(ImmutableListMultimap.of(a, v1, a, v2), ImmutableList.of(builder.values(v1), builder.values(v2)), sourceDistinct);
    ValuesNode child2 = builder.values(b);
    return builder.except(ImmutableListMultimap.of(c, a, c, b), ImmutableList.of(child1, child2), parentDistinct);
}
Also used : ValuesNode(io.trino.sql.planner.plan.ValuesNode) ExceptNode(io.trino.sql.planner.plan.ExceptNode) Symbol(io.trino.sql.planner.Symbol)

Example 18 with ValuesNode

use of io.trino.sql.planner.plan.ValuesNode in project trino by trinodb.

the class TestPlanNodeSearcher method joinNodePreorder.

/**
 * This method adds PlanNodeIds of JoinNodes to the builder in pre-order.
 * The plan tree must contain only JoinNodes and ValuesNodes.
 */
private static void joinNodePreorder(PlanNode root, ImmutableList.Builder<PlanNodeId> builder) {
    if (root instanceof ValuesNode) {
        return;
    }
    if (root instanceof JoinNode) {
        builder.add(root.getId());
        JoinNode join = (JoinNode) root;
        joinNodePreorder(join.getLeft(), builder);
        joinNodePreorder(join.getRight(), builder);
        return;
    }
    throw new IllegalArgumentException("unsupported node type: " + root.getClass().getSimpleName());
}
Also used : ValuesNode(io.trino.sql.planner.plan.ValuesNode) JoinNode(io.trino.sql.planner.plan.JoinNode)

Example 19 with ValuesNode

use of io.trino.sql.planner.plan.ValuesNode in project trino by trinodb.

the class TestVerifyOnlyOneOutputNode method testValidateSuccessful.

@Test
public void testValidateSuccessful() {
    // random seemingly valid plan
    PlanNode root = new OutputNode(idAllocator.getNextId(), new ProjectNode(idAllocator.getNextId(), new ValuesNode(idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of()), Assignments.of()), ImmutableList.of(), ImmutableList.of());
    new VerifyOnlyOneOutputNode().validate(root, null, PLANNER_CONTEXT, null, null, WarningCollector.NOOP);
}
Also used : ValuesNode(io.trino.sql.planner.plan.ValuesNode) OutputNode(io.trino.sql.planner.plan.OutputNode) PlanNode(io.trino.sql.planner.plan.PlanNode) ProjectNode(io.trino.sql.planner.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 20 with ValuesNode

use of io.trino.sql.planner.plan.ValuesNode in project trino by trinodb.

the class RelationPlanner method planSingleEmptyRow.

private PlanBuilder planSingleEmptyRow(Optional<Scope> parent) {
    Scope.Builder scope = Scope.builder();
    parent.ifPresent(scope::withOuterQueryParent);
    PlanNode values = new ValuesNode(idAllocator.getNextId(), 1);
    TranslationMap translations = new TranslationMap(outerContext, scope.build(), analysis, lambdaDeclarationToSymbolMap, ImmutableList.of());
    return new PlanBuilder(translations, values);
}
Also used : ValuesNode(io.trino.sql.planner.plan.ValuesNode) PlanNode(io.trino.sql.planner.plan.PlanNode) Scope(io.trino.sql.analyzer.Scope) PlanBuilder.newPlanBuilder(io.trino.sql.planner.PlanBuilder.newPlanBuilder)

Aggregations

ValuesNode (io.trino.sql.planner.plan.ValuesNode)36 Symbol (io.trino.sql.planner.Symbol)25 Expression (io.trino.sql.tree.Expression)15 PlanNode (io.trino.sql.planner.plan.PlanNode)14 Test (org.testng.annotations.Test)12 Row (io.trino.sql.tree.Row)11 JoinNode (io.trino.sql.planner.plan.JoinNode)10 ProjectNode (io.trino.sql.planner.plan.ProjectNode)10 ImmutableList (com.google.common.collect.ImmutableList)9 PlanNodeIdAllocator (io.trino.sql.planner.PlanNodeIdAllocator)8 PlanBuilder (io.trino.sql.planner.iterative.rule.test.PlanBuilder)8 FilterNode (io.trino.sql.planner.plan.FilterNode)8 ImmutableMap (com.google.common.collect.ImmutableMap)7 Session (io.trino.Session)7 MultiJoinNode (io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode)7 MultiJoinNode.toMultiJoinNode (io.trino.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode)7 List (java.util.List)7 Type (io.trino.spi.type.Type)6 DomainTranslator (io.trino.sql.planner.DomainTranslator)6 Map (java.util.Map)6