Search in sources :

Example 1 with UnnestAnalysis

use of io.trino.sql.analyzer.Analysis.UnnestAnalysis in project trino by trinodb.

the class RelationPlanner method planUnnest.

private RelationPlan planUnnest(PlanBuilder subPlan, Unnest node, List<Symbol> replicatedColumns, Optional<Expression> filter, Join.Type type, Scope outputScope) {
    subPlan = subPlan.appendProjections(node.getExpressions(), symbolAllocator, idAllocator);
    Map<Field, Symbol> allocations = analysis.getOutputDescriptor(node).getVisibleFields().stream().collect(toImmutableMap(Function.identity(), symbolAllocator::newSymbol));
    UnnestAnalysis unnestAnalysis = analysis.getUnnest(node);
    ImmutableList.Builder<UnnestNode.Mapping> mappings = ImmutableList.builder();
    for (Expression expression : node.getExpressions()) {
        Symbol input = subPlan.translate(expression);
        List<Symbol> outputs = unnestAnalysis.getMappings().get(NodeRef.of(expression)).stream().map(allocations::get).collect(toImmutableList());
        mappings.add(new UnnestNode.Mapping(input, outputs));
    }
    UnnestNode unnestNode = new UnnestNode(idAllocator.getNextId(), subPlan.getRoot(), replicatedColumns, mappings.build(), unnestAnalysis.getOrdinalityField().map(allocations::get), JoinNode.Type.typeConvert(type), filter);
    // Currently, it works out because, by construction, the order of the output symbols in the UnnestNode will match the order of the fields in the Join node.
    return new RelationPlan(unnestNode, outputScope, unnestNode.getOutputSymbols(), outerContext);
}
Also used : Field(io.trino.sql.analyzer.Field) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) CoalesceExpression(io.trino.sql.tree.CoalesceExpression) Expression(io.trino.sql.tree.Expression) SubqueryExpression(io.trino.sql.tree.SubqueryExpression) UnnestNode(io.trino.sql.planner.plan.UnnestNode) UnnestAnalysis(io.trino.sql.analyzer.Analysis.UnnestAnalysis) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 UnnestAnalysis (io.trino.sql.analyzer.Analysis.UnnestAnalysis)1 Field (io.trino.sql.analyzer.Field)1 UnnestNode (io.trino.sql.planner.plan.UnnestNode)1 CoalesceExpression (io.trino.sql.tree.CoalesceExpression)1 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)1 Expression (io.trino.sql.tree.Expression)1 SubqueryExpression (io.trino.sql.tree.SubqueryExpression)1