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