Search in sources :

Example 1 with ExplainAnalyzeNode

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

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

the class LogicalPlanner method createExplainAnalyzePlan.

private RelationPlan createExplainAnalyzePlan(Analysis analysis, ExplainAnalyze statement) {
    RelationPlan underlyingPlan = planStatementWithoutOutput(analysis, statement.getStatement());
    PlanNode root = underlyingPlan.getRoot();
    Scope scope = analysis.getScope(statement);
    Symbol outputSymbol = symbolAllocator.newSymbol(scope.getRelationType().getFieldByIndex(0));
    ImmutableList.Builder<Symbol> actualOutputs = ImmutableList.builder();
    RelationType outputDescriptor = analysis.getOutputDescriptor(statement.getStatement());
    for (Field field : outputDescriptor.getVisibleFields()) {
        int fieldIndex = outputDescriptor.indexOf(field);
        Symbol symbol = underlyingPlan.getSymbol(fieldIndex);
        actualOutputs.add(symbol);
    }
    root = new ExplainAnalyzeNode(idAllocator.getNextId(), root, outputSymbol, actualOutputs.build(), statement.isVerbose());
    return new RelationPlan(root, scope, ImmutableList.of(outputSymbol), Optional.empty());
}
Also used : Field(io.trino.sql.analyzer.Field) PlanNode(io.trino.sql.planner.plan.PlanNode) Scope(io.trino.sql.analyzer.Scope) ExplainAnalyzeNode(io.trino.sql.planner.plan.ExplainAnalyzeNode) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) RelationType(io.trino.sql.analyzer.RelationType)

Aggregations

ExplainAnalyzeNode (io.trino.sql.planner.plan.ExplainAnalyzeNode)2 PlanNode (io.trino.sql.planner.plan.PlanNode)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 Field (io.trino.sql.analyzer.Field)1 RelationType (io.trino.sql.analyzer.RelationType)1 Scope (io.trino.sql.analyzer.Scope)1 Symbol (io.trino.sql.planner.Symbol)1 OutputNode (io.trino.sql.planner.plan.OutputNode)1 ProjectNode (io.trino.sql.planner.plan.ProjectNode)1 ValuesNode (io.trino.sql.planner.plan.ValuesNode)1 Test (org.testng.annotations.Test)1