Search in sources :

Example 6 with RelationType

use of io.trino.sql.analyzer.RelationType 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 7 with RelationType

use of io.trino.sql.analyzer.RelationType 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

ImmutableList (com.google.common.collect.ImmutableList)7 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)7 RelationType (io.trino.sql.analyzer.RelationType)7 Field (io.trino.sql.analyzer.Field)5 PlanNode (io.trino.sql.planner.plan.PlanNode)5 Type (io.trino.spi.type.Type)4 TypeSignatureTranslator.toSqlType (io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType)4 PlanBuilder.newPlanBuilder (io.trino.sql.planner.PlanBuilder.newPlanBuilder)4 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)4 Expression (io.trino.sql.tree.Expression)4 ProjectNode (io.trino.sql.planner.plan.ProjectNode)3 Cast (io.trino.sql.tree.Cast)3 Row (io.trino.sql.tree.Row)3 SubqueryExpression (io.trino.sql.tree.SubqueryExpression)3 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)2 NotExpression (io.trino.sql.tree.NotExpression)2 QuantifiedComparisonExpression (io.trino.sql.tree.QuantifiedComparisonExpression)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Verify.verify (com.google.common.base.Verify.verify)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1