Search in sources :

Example 11 with ValuesNode

use of io.prestosql.spi.plan.ValuesNode in project hetu-core by openlookeng.

the class QueryPlanner method planImplicitTable.

private RelationPlan planImplicitTable() {
    List<RowExpression> emptyRow = ImmutableList.of();
    Scope scope = Scope.create();
    return new RelationPlan(new ValuesNode(idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of(emptyRow)), scope, ImmutableList.of());
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) Scope(io.prestosql.sql.analyzer.Scope) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) RowExpression(io.prestosql.spi.relation.RowExpression)

Example 12 with ValuesNode

use of io.prestosql.spi.plan.ValuesNode in project hetu-core by openlookeng.

the class RelationPlanner method visitValues.

@Override
protected RelationPlan visitValues(Values node, Void context) {
    Scope scope = analysis.getScope(node);
    ImmutableList.Builder<Symbol> outputSymbolsBuilder = ImmutableList.builder();
    for (Field field : scope.getRelationType().getVisibleFields()) {
        Symbol symbol = planSymbolAllocator.newSymbol(field);
        outputSymbolsBuilder.add(symbol);
    }
    ImmutableList.Builder<List<RowExpression>> rows = ImmutableList.builder();
    for (Expression row : node.getRows()) {
        ImmutableList.Builder<RowExpression> values = ImmutableList.builder();
        if (row instanceof Row) {
            for (Expression item : ((Row) row).getItems()) {
                Expression expression = Coercer.addCoercions(item, analysis);
                values.add(castToRowExpression(ExpressionTreeRewriter.rewriteWith(new ParameterRewriter(analysis.getParameters(), analysis), expression)));
            }
        } else {
            Expression expression = Coercer.addCoercions(row, analysis);
            values.add(castToRowExpression(ExpressionTreeRewriter.rewriteWith(new ParameterRewriter(analysis.getParameters(), analysis), expression)));
        }
        rows.add(values.build());
    }
    ValuesNode valuesNode = new ValuesNode(idAllocator.getNextId(), outputSymbolsBuilder.build(), rows.build());
    return new RelationPlan(valuesNode, scope, outputSymbolsBuilder.build());
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) Symbol(io.prestosql.spi.plan.Symbol) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Field(io.prestosql.sql.analyzer.Field) Scope(io.prestosql.sql.analyzer.Scope) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) RowExpression(io.prestosql.spi.relation.RowExpression) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Row(io.prestosql.sql.tree.Row)

Example 13 with ValuesNode

use of io.prestosql.spi.plan.ValuesNode in project hetu-core by openlookeng.

the class RelationPlanner method planLateralJoin.

private RelationPlan planLateralJoin(Join join, RelationPlan leftPlan, Lateral lateral) {
    RelationPlan rightPlan = process(lateral.getQuery(), null);
    PlanBuilder leftPlanBuilder = initializePlanBuilder(leftPlan);
    PlanBuilder rightPlanBuilder = initializePlanBuilder(rightPlan);
    Expression filterExpression;
    if (!join.getCriteria().isPresent()) {
        filterExpression = TRUE_LITERAL;
    } else {
        JoinCriteria criteria = join.getCriteria().get();
        if (criteria instanceof JoinUsing || criteria instanceof NaturalJoin) {
            throw notSupportedException(join, "Lateral join with criteria other than ON");
        }
        filterExpression = (Expression) getOnlyElement(criteria.getNodes());
    }
    List<Symbol> rewriterOutputSymbols = ImmutableList.<Symbol>builder().addAll(leftPlan.getFieldMappings()).addAll(rightPlan.getFieldMappings()).build();
    // this node is not used in the plan. It is only used for creating the TranslationMap.
    PlanNode dummy = new ValuesNode(idAllocator.getNextId(), ImmutableList.<Symbol>builder().addAll(leftPlanBuilder.getRoot().getOutputSymbols()).addAll(rightPlanBuilder.getRoot().getOutputSymbols()).build(), ImmutableList.of());
    RelationPlan intermediateRelationPlan = new RelationPlan(dummy, analysis.getScope(join), rewriterOutputSymbols);
    TranslationMap translationMap = new TranslationMap(intermediateRelationPlan, analysis, lambdaDeclarationToSymbolMap);
    translationMap.setFieldMappings(rewriterOutputSymbols);
    translationMap.putExpressionMappingsFrom(leftPlanBuilder.getTranslations());
    translationMap.putExpressionMappingsFrom(rightPlanBuilder.getTranslations());
    Expression rewrittenFilterCondition = translationMap.rewrite(filterExpression);
    PlanBuilder planBuilder = subqueryPlanner.appendLateralJoin(leftPlanBuilder, rightPlanBuilder, lateral.getQuery(), true, LateralJoinNode.Type.typeConvert(join.getType()), rewrittenFilterCondition);
    List<Symbol> outputSymbols = ImmutableList.<Symbol>builder().addAll(leftPlan.getRoot().getOutputSymbols()).addAll(rightPlan.getRoot().getOutputSymbols()).build();
    return new RelationPlan(planBuilder.getRoot(), analysis.getScope(join), outputSymbols);
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) PlanNode(io.prestosql.spi.plan.PlanNode) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Symbol(io.prestosql.spi.plan.Symbol) JoinCriteria(io.prestosql.sql.tree.JoinCriteria) JoinUsing(io.prestosql.sql.tree.JoinUsing) NaturalJoin(io.prestosql.sql.tree.NaturalJoin)

Example 14 with ValuesNode

use of io.prestosql.spi.plan.ValuesNode in project hetu-core by openlookeng.

the class DistributedExecutionPlanner method collectSources.

private List<MarkerSplitSource> collectSources(Map<PlanFragmentId, Object> leftmostSources, Object source) {
    if (source instanceof ValuesNode) {
        // TODO-cp-I2X9J6: should we worry about dependencies about Values operators, when it's the "left" of a join?
        return ImmutableList.of();
    }
    if (source instanceof RemoteSourceNode) {
        List<PlanFragmentId> fragments = ((RemoteSourceNode) source).getSourceFragmentIds();
        if (fragments.size() == 1) {
            return collectSources(leftmostSources, leftmostSources.get(fragments.get(0)));
        }
        List<MarkerSplitSource> sources = new ArrayList<>();
        for (PlanFragmentId id : fragments) {
            sources.addAll(collectSources(leftmostSources, leftmostSources.get(id)));
        }
        // Adding all these sources as "union dependencies" for each other, to make sure they produce the same set of markers.
        for (MarkerSplitSource unionSource : sources) {
            unionSource.addUnionSources(sources);
        }
        return sources;
    }
    // Must be a split source
    return ImmutableList.of((MarkerSplitSource) source);
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) RemoteSourceNode(io.prestosql.sql.planner.plan.RemoteSourceNode) MarkerSplitSource(io.prestosql.snapshot.MarkerSplitSource) ArrayList(java.util.ArrayList) PlanFragmentId(io.prestosql.sql.planner.plan.PlanFragmentId)

Example 15 with ValuesNode

use of io.prestosql.spi.plan.ValuesNode in project hetu-core by openlookeng.

the class PruneCountAggregationOverScalar method apply.

@Override
public Result apply(AggregationNode parent, Captures captures, Context context) {
    if (!parent.hasDefaultOutput() || parent.getOutputSymbols().size() != 1) {
        return Result.empty();
    }
    Map<Symbol, AggregationNode.Aggregation> assignments = parent.getAggregations();
    for (Map.Entry<Symbol, AggregationNode.Aggregation> entry : assignments.entrySet()) {
        AggregationNode.Aggregation aggregation = entry.getValue();
        requireNonNull(aggregation, "aggregation is null");
        if (!functionResolution.isCountFunction(aggregation.getFunctionHandle()) || !aggregation.getArguments().isEmpty()) {
            return Result.empty();
        }
    }
    if (!assignments.isEmpty() && isScalar(parent.getSource(), context.getLookup())) {
        return Result.ofPlanNode(new ValuesNode(parent.getId(), parent.getOutputSymbols(), ImmutableList.of(ImmutableList.of(castToRowExpression(new LongLiteral("1"))))));
    }
    return Result.empty();
}
Also used : ValuesNode(io.prestosql.spi.plan.ValuesNode) LongLiteral(io.prestosql.sql.tree.LongLiteral) Symbol(io.prestosql.spi.plan.Symbol) AggregationNode(io.prestosql.spi.plan.AggregationNode) Map(java.util.Map)

Aggregations

ValuesNode (io.prestosql.spi.plan.ValuesNode)26 Symbol (io.prestosql.spi.plan.Symbol)16 Test (org.testng.annotations.Test)12 PlanNode (io.prestosql.spi.plan.PlanNode)8 RowExpression (io.prestosql.spi.relation.RowExpression)8 List (java.util.List)8 ImmutableList (com.google.common.collect.ImmutableList)6 JoinNode (io.prestosql.spi.plan.JoinNode)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 ProjectNode (io.prestosql.spi.plan.ProjectNode)5 MultiJoinNode (io.prestosql.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode)5 MultiJoinNode.toMultiJoinNode (io.prestosql.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode.toMultiJoinNode)5 PlanBuilder (io.prestosql.sql.planner.iterative.rule.test.PlanBuilder)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)4 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)4 Session (io.prestosql.Session)3 OutputNode (io.prestosql.sql.planner.plan.OutputNode)3 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)3 Expression (io.prestosql.sql.tree.Expression)3