Skip to content

Commit

Permalink
Remove unneeded JoinGraph#assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
sopel39 committed Aug 27, 2019
1 parent 42b10c6 commit ca0d25f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
import io.prestosql.sql.planner.Symbol;
import io.prestosql.sql.planner.iterative.Rule;
import io.prestosql.sql.planner.optimizations.joins.JoinGraph;
import io.prestosql.sql.planner.plan.Assignments;
import io.prestosql.sql.planner.plan.FilterNode;
import io.prestosql.sql.planner.plan.JoinNode;
import io.prestosql.sql.planner.plan.PlanNode;
import io.prestosql.sql.planner.plan.PlanNodeId;
import io.prestosql.sql.planner.plan.ProjectNode;
import io.prestosql.sql.tree.Expression;

import java.util.HashMap;
Expand Down Expand Up @@ -201,13 +199,6 @@ public static PlanNode buildJoinTree(List<Symbol> expectedOutputSymbols, JoinGra
filter);
}

if (graph.getAssignments().isPresent()) {
result = new ProjectNode(
idAllocator.getNextId(),
result,
Assignments.copyOf(graph.getAssignments().get()));
}

// If needed, introduce a projection to constrain the outputs to what was originally expected
// Some nodes are sensitive to what's produced (e.g., DistinctLimit node)
return restrictOutputs(idAllocator, result, ImmutableSet.copyOf(expectedOutputSymbols)).orElse(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
*/
public class JoinGraph
{
private final Optional<Map<Symbol, Expression>> assignments;
private final List<Expression> filters;
private final List<PlanNode> nodes; // nodes in order of their appearance in tree plan (left, right, parent)
private final Multimap<PlanNodeId, Edge> edges;
Expand All @@ -64,42 +63,30 @@ public static JoinGraph buildFrom(PlanNode plan, Lookup lookup, PlanNodeIdAlloca

public JoinGraph(PlanNode node)
{
this(ImmutableList.of(node), ImmutableMultimap.of(), node.getId(), ImmutableList.of(), Optional.empty(), false);
this(ImmutableList.of(node), ImmutableMultimap.of(), node.getId(), ImmutableList.of(), false);
}

public JoinGraph(
List<PlanNode> nodes,
Multimap<PlanNodeId, Edge> edges,
PlanNodeId rootId,
List<Expression> filters,
Optional<Map<Symbol, Expression>> assignments,
boolean containsCrossJoin)
{
this.nodes = nodes;
this.edges = edges;
this.rootId = rootId;
this.filters = filters;
this.assignments = assignments;
this.containsCrossJoin = containsCrossJoin;
}

public JoinGraph withAssignments(Map<Symbol, Expression> assignments)
{
return new JoinGraph(nodes, edges, rootId, filters, Optional.of(assignments), containsCrossJoin);
}

public Optional<Map<Symbol, Expression>> getAssignments()
{
return assignments;
}

public JoinGraph withFilter(Expression expression)
{
ImmutableList.Builder<Expression> filters = ImmutableList.builder();
filters.addAll(this.filters);
filters.add(expression);

return new JoinGraph(nodes, edges, rootId, filters.build(), assignments, containsCrossJoin);
return new JoinGraph(nodes, edges, rootId, filters.build(), containsCrossJoin);
}

public List<Expression> getFilters()
Expand Down Expand Up @@ -197,7 +184,7 @@ private JoinGraph joinWith(JoinGraph other, List<JoinNode.EquiJoinClause> joinCl
edges.put(right.getId(), new Edge(left, rightSymbol, leftSymbol));
}

return new JoinGraph(nodes, edges.build(), newRoot, joinedFilters, Optional.empty(), this.containsCrossJoin || containsCrossJoin);
return new JoinGraph(nodes, edges.build(), newRoot, joinedFilters, this.containsCrossJoin || containsCrossJoin);
}

private static class Builder
Expand Down Expand Up @@ -250,11 +237,6 @@ public JoinGraph visitJoin(JoinNode node, Context context)
@Override
public JoinGraph visitProject(ProjectNode node, Context context)
{
if (node.isIdentity()) {
JoinGraph graph = node.getSource().accept(this, context);
return graph.withAssignments(node.getAssignments().getMap());
}

Optional<PlanNode> rewrittenNode = pushProjectionThroughJoin(node, lookup, planNodeIdAllocator);
if (rewrittenNode.isPresent()) {
return rewrittenNode.get().accept(this, context);
Expand All @@ -276,7 +258,7 @@ public JoinGraph visitGroupReference(GroupReference node, Context context)

private boolean isTrivialGraph(JoinGraph graph)
{
return graph.nodes.size() < 2 && graph.edges.isEmpty() && graph.filters.isEmpty() && !graph.assignments.isPresent();
return graph.nodes.size() < 2 && graph.edges.isEmpty() && graph.filters.isEmpty();
}

private JoinGraph replacementGraph(PlanNode oldNode, PlanNode newNode, Context context)
Expand Down

0 comments on commit ca0d25f

Please sign in to comment.