Skip to content

Commit

Permalink
Reuse original node Ids
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiafi authored and martint committed Sep 28, 2019
1 parent 88dd641 commit 5e80f1e
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ private PlanNode replaceExpressionsWithSymbols(PlanNode planNode, Map<NodeRef<Ex
return planNode;
}

return SimplePlanRewriter.rewriteWith(new ExpressionReplacer(idAllocator, mapping), planNode, null);
return SimplePlanRewriter.rewriteWith(new ExpressionReplacer(mapping), planNode, null);
}

private static class ColumnReferencesExtractor
Expand Down Expand Up @@ -557,12 +557,10 @@ protected Void visitIdentifier(Identifier node, ImmutableSet.Builder<NodeRef<Exp
private static class ExpressionReplacer
extends SimplePlanRewriter<Void>
{
private final PlanNodeIdAllocator idAllocator;
private final Map<NodeRef<Expression>, Expression> mapping;

public ExpressionReplacer(PlanNodeIdAllocator idAllocator, Map<NodeRef<Expression>, Expression> mapping)
public ExpressionReplacer(Map<NodeRef<Expression>, Expression> mapping)
{
this.idAllocator = requireNonNull(idAllocator, "idAllocator is null");
this.mapping = requireNonNull(mapping, "mapping is null");
}

Expand All @@ -574,14 +572,14 @@ public PlanNode visitProject(ProjectNode node, RewriteContext<Void> context)
Assignments assignments = rewrittenNode.getAssignments()
.rewrite(expression -> replaceExpression(expression, mapping));

return new ProjectNode(idAllocator.getNextId(), rewrittenNode.getSource(), assignments);
return new ProjectNode(node.getId(), rewrittenNode.getSource(), assignments);
}

@Override
public PlanNode visitFilter(FilterNode node, RewriteContext<Void> context)
{
FilterNode rewrittenNode = (FilterNode) context.defaultRewrite(node);
return new FilterNode(idAllocator.getNextId(), rewrittenNode.getSource(), replaceExpression(rewrittenNode.getPredicate(), mapping));
return new FilterNode(node.getId(), rewrittenNode.getSource(), replaceExpression(rewrittenNode.getPredicate(), mapping));
}

@Override
Expand All @@ -594,7 +592,7 @@ public PlanNode visitValues(ValuesNode node, RewriteContext<Void> context)
.collect(toImmutableList()))
.collect(toImmutableList());
return new ValuesNode(
idAllocator.getNextId(),
node.getId(),
rewrittenNode.getOutputSymbols(),
rewrittenRows);
}
Expand Down

0 comments on commit 5e80f1e

Please sign in to comment.