Search in sources :

Example 1 with OutputNode

use of com.facebook.presto.sql.planner.plan.OutputNode in project presto by prestodb.

the class TestVerifyOnlyOneOutputNode method testValidateFailed.

@Test(expectedExceptions = IllegalStateException.class)
public void testValidateFailed() throws Exception {
    // random plan with 2 output nodes
    PlanNode root = new OutputNode(idAllocator.getNextId(), new ExplainAnalyzeNode(idAllocator.getNextId(), new OutputNode(idAllocator.getNextId(), new ProjectNode(idAllocator.getNextId(), new ValuesNode(idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of()), Assignments.of()), ImmutableList.of(), ImmutableList.of()), new Symbol("a")), ImmutableList.of(), ImmutableList.of());
    new VerifyOnlyOneOutputNode().validate(root, null, null, null, null);
}
Also used : ValuesNode(com.facebook.presto.sql.planner.plan.ValuesNode) OutputNode(com.facebook.presto.sql.planner.plan.OutputNode) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) ExplainAnalyzeNode(com.facebook.presto.sql.planner.plan.ExplainAnalyzeNode) Symbol(com.facebook.presto.sql.planner.Symbol) ProjectNode(com.facebook.presto.sql.planner.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 2 with OutputNode

use of com.facebook.presto.sql.planner.plan.OutputNode in project presto by prestodb.

the class LogicalPlanner method planStatement.

public PlanNode planStatement(Analysis analysis, Statement statement) {
    if (statement instanceof CreateTableAsSelect && analysis.isCreateTableAsSelectNoOp()) {
        checkState(analysis.getCreateTableDestination().isPresent(), "Table destination is missing");
        List<Expression> emptyRow = ImmutableList.of();
        PlanNode source = new ValuesNode(idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of(emptyRow));
        return new OutputNode(idAllocator.getNextId(), source, ImmutableList.of(), ImmutableList.of());
    }
    return createOutputPlan(planStatementWithoutOutput(analysis, statement), analysis);
}
Also used : ValuesNode(com.facebook.presto.sql.planner.plan.ValuesNode) OutputNode(com.facebook.presto.sql.planner.plan.OutputNode) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) Expression(com.facebook.presto.sql.tree.Expression) CreateTableAsSelect(com.facebook.presto.sql.tree.CreateTableAsSelect)

Example 3 with OutputNode

use of com.facebook.presto.sql.planner.plan.OutputNode in project presto by prestodb.

the class LogicalPlanner method createOutputPlan.

private PlanNode createOutputPlan(RelationPlan plan, Analysis analysis) {
    ImmutableList.Builder<Symbol> outputs = ImmutableList.builder();
    ImmutableList.Builder<String> names = ImmutableList.builder();
    int columnNumber = 0;
    RelationType outputDescriptor = analysis.getOutputDescriptor();
    for (Field field : outputDescriptor.getVisibleFields()) {
        String name = field.getName().orElse("_col" + columnNumber);
        names.add(name);
        int fieldIndex = outputDescriptor.indexOf(field);
        Symbol symbol = plan.getSymbol(fieldIndex);
        outputs.add(symbol);
        columnNumber++;
    }
    return new OutputNode(idAllocator.getNextId(), plan.getRoot(), names.build(), outputs.build());
}
Also used : Field(com.facebook.presto.sql.analyzer.Field) OutputNode(com.facebook.presto.sql.planner.plan.OutputNode) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) RelationType(com.facebook.presto.sql.analyzer.RelationType)

Example 4 with OutputNode

use of com.facebook.presto.sql.planner.plan.OutputNode in project presto by prestodb.

the class TestVerifyOnlyOneOutputNode method testValidateSuccessful.

@Test
public void testValidateSuccessful() throws Exception {
    // 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, null, null, null);
}
Also used : ValuesNode(com.facebook.presto.sql.planner.plan.ValuesNode) OutputNode(com.facebook.presto.sql.planner.plan.OutputNode) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) ProjectNode(com.facebook.presto.sql.planner.plan.ProjectNode) Test(org.testng.annotations.Test)

Aggregations

OutputNode (com.facebook.presto.sql.planner.plan.OutputNode)4 PlanNode (com.facebook.presto.sql.planner.plan.PlanNode)3 ValuesNode (com.facebook.presto.sql.planner.plan.ValuesNode)3 ProjectNode (com.facebook.presto.sql.planner.plan.ProjectNode)2 Test (org.testng.annotations.Test)2 Field (com.facebook.presto.sql.analyzer.Field)1 RelationType (com.facebook.presto.sql.analyzer.RelationType)1 Symbol (com.facebook.presto.sql.planner.Symbol)1 ExplainAnalyzeNode (com.facebook.presto.sql.planner.plan.ExplainAnalyzeNode)1 CreateTableAsSelect (com.facebook.presto.sql.tree.CreateTableAsSelect)1 Expression (com.facebook.presto.sql.tree.Expression)1 ImmutableCollectors.toImmutableList (com.facebook.presto.util.ImmutableCollectors.toImmutableList)1 ImmutableList (com.google.common.collect.ImmutableList)1