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);
}
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");
}
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);
}
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());
}
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);
}
Aggregations