use of io.prestosql.spi.plan.ProjectNode in project hetu-core by openlookeng.
the class ImplementIntersectAsUnion method apply.
@Override
public Result apply(IntersectNode node, Captures captures, Context context) {
SetOperationNodeTranslator translator = new SetOperationNodeTranslator(metadata, context.getSymbolAllocator(), context.getIdAllocator());
SetOperationNodeTranslator.TranslationResult result = translator.makeSetContainmentPlan(node);
return Result.ofPlanNode(new ProjectNode(context.getIdAllocator().getNextId(), new FilterNode(context.getIdAllocator().getNextId(), result.getPlanNode(), castToRowExpression(and(result.getPresentExpressions()))), AssignmentUtils.identityAsSymbolReferences(node.getOutputSymbols())));
}
use of io.prestosql.spi.plan.ProjectNode in project hetu-core by openlookeng.
the class ImplementLimitWithTies method apply.
@Override
public Result apply(LimitNode parent, Captures captures, Context context) {
PlanNode child = captures.get(CHILD);
Symbol rankSymbol = context.getSymbolAllocator().newSymbol("rank_num", BIGINT);
WindowNode.Frame frame = new WindowNode.Frame(WindowFrameType.RANGE, FrameBoundType.UNBOUNDED_PRECEDING, Optional.empty(), FrameBoundType.CURRENT_ROW, Optional.empty(), Optional.empty(), Optional.empty());
FunctionHandle functionHandle = metadata.getFunctionAndTypeManager().lookupFunction("rank", ImmutableList.of());
WindowNode.Function rankFunction = new WindowNode.Function(call(QualifiedObjectName.valueOf(DEFAULT_NAMESPACE, "rank").toString(), functionHandle, BIGINT), ImmutableList.of(), frame);
WindowNode windowNode = new WindowNode(context.getIdAllocator().getNextId(), child, new WindowNode.Specification(ImmutableList.of(), parent.getTiesResolvingScheme()), ImmutableMap.of(rankSymbol, rankFunction), Optional.empty(), ImmutableSet.of(), 0);
FilterNode filterNode = new FilterNode(context.getIdAllocator().getNextId(), windowNode, castToRowExpression(new ComparisonExpression(ComparisonExpression.Operator.LESS_THAN_OR_EQUAL, toSymbolReference(rankSymbol), new GenericLiteral("BIGINT", Long.toString(parent.getCount())))));
ProjectNode projectNode = new ProjectNode(context.getIdAllocator().getNextId(), filterNode, AssignmentUtils.identityAsSymbolReferences(parent.getOutputSymbols()));
return Result.ofPlanNode(projectNode);
}
use of io.prestosql.spi.plan.ProjectNode in project hetu-core by openlookeng.
the class ImplementOffset method apply.
@Override
public Result apply(OffsetNode parent, Captures captures, Context context) {
Symbol rowNumberSymbol = context.getSymbolAllocator().newSymbol("row_number", BIGINT);
RowNumberNode rowNumberNode = new RowNumberNode(context.getIdAllocator().getNextId(), parent.getSource(), ImmutableList.of(), rowNumberSymbol, Optional.empty(), Optional.empty());
FilterNode filterNode = new FilterNode(context.getIdAllocator().getNextId(), rowNumberNode, castToRowExpression(new ComparisonExpression(ComparisonExpression.Operator.GREATER_THAN, toSymbolReference(rowNumberSymbol), new GenericLiteral("BIGINT", Long.toString(parent.getCount())))));
ProjectNode projectNode = new ProjectNode(context.getIdAllocator().getNextId(), filterNode, AssignmentUtils.identityAsSymbolReferences(parent.getOutputSymbols()));
return Result.ofPlanNode(projectNode);
}
use of io.prestosql.spi.plan.ProjectNode in project hetu-core by openlookeng.
the class InlineProjections method apply.
@Override
public Result apply(ProjectNode parent, Captures captures, Context context) {
ProjectNode child = captures.get(CHILD);
Sets.SetView<Symbol> targets = extractInliningTargets(parent, child);
if (targets.isEmpty()) {
return Result.empty();
}
// inline the expressions
Assignments assignments = child.getAssignments().filter(targets::contains);
Map<Symbol, RowExpression> parentAssignments = parent.getAssignments().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> (inlineReferences(entry.getValue(), assignments))));
// Synthesize identity assignments for the inputs of expressions that were inlined
// to place in the child projection.
// If all assignments end up becoming identity assignments, they'll get pruned by
// other rules
Set<Symbol> inputs = child.getAssignments().entrySet().stream().filter(entry -> targets.contains(entry.getKey())).map(Map.Entry::getValue).flatMap(entry -> extractInputs(entry).stream()).collect(toSet());
Assignments.Builder childAssignments = Assignments.builder();
for (Map.Entry<Symbol, RowExpression> assignment : child.getAssignments().entrySet()) {
if (!targets.contains(assignment.getKey())) {
childAssignments.put(assignment);
}
}
boolean allTranslated = child.getAssignments().entrySet().stream().map(Map.Entry::getValue).noneMatch(OriginalExpressionUtils::isExpression);
for (Symbol input : inputs) {
if (allTranslated) {
Type inputType = context.getSymbolAllocator().getSymbols().get(input);
childAssignments.put(input, new VariableReferenceExpression(input.getName(), inputType));
} else {
childAssignments.put(input, castToRowExpression(toSymbolReference(input)));
}
}
return Result.ofPlanNode(new ProjectNode(parent.getId(), new ProjectNode(child.getId(), child.getSource(), childAssignments.build()), Assignments.copyOf(parentAssignments)));
}
use of io.prestosql.spi.plan.ProjectNode in project hetu-core by openlookeng.
the class PushProjectionIntoTableScan method apply.
@Override
public Result apply(ProjectNode project, Captures captures, Context context) {
TableScanNode tableScan = captures.get(TABLE_SCAN);
List<ConnectorExpression> projections;
try {
projections = project.getAssignments().getExpressions().stream().map(expression -> ConnectorExpressionTranslator.translate(expression)).collect(toImmutableList());
} catch (UnsupportedOperationException e) {
// rewritten in terms of the new assignments for the columns passed in #2
return Result.empty();
}
Map<String, ColumnHandle> assignments = tableScan.getAssignments().entrySet().stream().collect(toImmutableMap(entry -> entry.getKey().getName(), Map.Entry::getValue));
Optional<ProjectionApplicationResult<TableHandle>> result = metadata.applyProjection(context.getSession(), tableScan.getTable(), projections, assignments);
if (!result.isPresent()) {
return Result.empty();
}
List<Symbol> newScanOutputs = new ArrayList<>();
Map<Symbol, ColumnHandle> newScanAssignments = new HashMap<>();
Map<String, Symbol> variableMappings = new HashMap<>();
for (ProjectionApplicationResult.Assignment assignment : result.get().getAssignments()) {
Symbol symbol = context.getSymbolAllocator().newSymbol(assignment.getVariable(), assignment.getType());
newScanOutputs.add(symbol);
newScanAssignments.put(symbol, assignment.getColumn());
variableMappings.put(assignment.getVariable(), symbol);
}
// TODO: ensure newProjections.size == original projections.size
List<RowExpression> newProjections = result.get().getProjections().stream().map(expression -> ConnectorExpressionTranslator.translate(expression, variableMappings, new LiteralEncoder(metadata))).collect(toImmutableList());
Assignments.Builder newProjectionAssignments = Assignments.builder();
for (int i = 0; i < project.getOutputSymbols().size(); i++) {
newProjectionAssignments.put(project.getOutputSymbols().get(i), newProjections.get(i));
}
return Result.ofPlanNode(new ProjectNode(context.getIdAllocator().getNextId(), TableScanNode.newInstance(tableScan.getId(), result.get().getHandle(), newScanOutputs, newScanAssignments, tableScan.getStrategy(), tableScan.getReuseTableScanMappingId(), tableScan.getConsumerTableScanNodeCount(), tableScan.isForDelete()), newProjectionAssignments.build()));
}
Aggregations