Search in sources :

Example 1 with OutputNode

use of io.trino.sql.planner.plan.OutputNode 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 2 with OutputNode

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

the class TestVerifyOnlyOneOutputNode method testValidateFailed.

@Test
public void testValidateFailed() {
    // 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(), false), ImmutableList.of(), ImmutableList.of());
    assertThatThrownBy(() -> new VerifyOnlyOneOutputNode().validate(root, null, PLANNER_CONTEXT, null, null, WarningCollector.NOOP)).isInstanceOf(IllegalStateException.class).hasMessage("Expected plan to have single instance of OutputNode");
}
Also used : ValuesNode(io.trino.sql.planner.plan.ValuesNode) OutputNode(io.trino.sql.planner.plan.OutputNode) PlanNode(io.trino.sql.planner.plan.PlanNode) ExplainAnalyzeNode(io.trino.sql.planner.plan.ExplainAnalyzeNode) Symbol(io.trino.sql.planner.Symbol) ProjectNode(io.trino.sql.planner.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 3 with OutputNode

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

the class LogicalPlanner method planStatement.

public PlanNode planStatement(Analysis analysis, Statement statement) {
    if ((statement instanceof CreateTableAsSelect && analysis.getCreate().orElseThrow().isCreateTableAsSelectNoOp()) || statement instanceof RefreshMaterializedView && analysis.isSkipMaterializedViewRefresh()) {
        Symbol symbol = symbolAllocator.newSymbol("rows", BIGINT);
        PlanNode source = new ValuesNode(idAllocator.getNextId(), ImmutableList.of(symbol), ImmutableList.of(new Row(ImmutableList.of(new GenericLiteral("BIGINT", "0")))));
        return new OutputNode(idAllocator.getNextId(), source, ImmutableList.of("rows"), ImmutableList.of(symbol));
    }
    return createOutputPlan(planStatementWithoutOutput(analysis, statement), analysis);
}
Also used : ValuesNode(io.trino.sql.planner.plan.ValuesNode) OutputNode(io.trino.sql.planner.plan.OutputNode) PlanNode(io.trino.sql.planner.plan.PlanNode) RefreshMaterializedView(io.trino.sql.tree.RefreshMaterializedView) CreateTableAsSelect(io.trino.sql.tree.CreateTableAsSelect) Row(io.trino.sql.tree.Row) GenericLiteral(io.trino.sql.tree.GenericLiteral)

Example 4 with OutputNode

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

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(io.trino.sql.analyzer.Field) OutputNode(io.trino.sql.planner.plan.OutputNode) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) RelationType(io.trino.sql.analyzer.RelationType)

Example 5 with OutputNode

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

the class MetricComparator method getEstimatedValuesInternal.

private static List<OptionalDouble> getEstimatedValuesInternal(List<Metric> metrics, String query, QueryRunner runner, Session session) // TODO inline back this method
{
    Plan queryPlan = runner.createPlan(session, query, WarningCollector.NOOP);
    OutputNode outputNode = (OutputNode) queryPlan.getRoot();
    PlanNodeStatsEstimate outputNodeStats = queryPlan.getStatsAndCosts().getStats().getOrDefault(queryPlan.getRoot().getId(), PlanNodeStatsEstimate.unknown());
    StatsContext statsContext = buildStatsContext(queryPlan, outputNode);
    return getEstimatedValues(metrics, outputNodeStats, statsContext);
}
Also used : OutputNode(io.trino.sql.planner.plan.OutputNode) PlanNodeStatsEstimate(io.trino.cost.PlanNodeStatsEstimate) Plan(io.trino.sql.planner.Plan)

Aggregations

OutputNode (io.trino.sql.planner.plan.OutputNode)5 PlanNode (io.trino.sql.planner.plan.PlanNode)3 ValuesNode (io.trino.sql.planner.plan.ValuesNode)3 ProjectNode (io.trino.sql.planner.plan.ProjectNode)2 Test (org.testng.annotations.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 PlanNodeStatsEstimate (io.trino.cost.PlanNodeStatsEstimate)1 Field (io.trino.sql.analyzer.Field)1 RelationType (io.trino.sql.analyzer.RelationType)1 Plan (io.trino.sql.planner.Plan)1 Symbol (io.trino.sql.planner.Symbol)1 ExplainAnalyzeNode (io.trino.sql.planner.plan.ExplainAnalyzeNode)1 CreateTableAsSelect (io.trino.sql.tree.CreateTableAsSelect)1 GenericLiteral (io.trino.sql.tree.GenericLiteral)1 RefreshMaterializedView (io.trino.sql.tree.RefreshMaterializedView)1 Row (io.trino.sql.tree.Row)1