Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lookup#resolveGroup method and make Lookup#resolve depricated #8698

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public PlanNode optimize(PlanNode plan, Session session, Map<Symbol, Type> types
}

Memo memo = new Memo(idAllocator, plan);
Lookup lookup = Lookup.from(memo::resolve);
Lookup lookup = Lookup.from(planNode -> ImmutableList.of(memo.resolve(planNode)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use Collections.singletonList() instead of ImmutableList.of with single argument. But up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ImmutableList.of() plays better with ImmutableList.copyOf.

Matcher matcher = new PlanNodeMatcher(lookup);

Duration timeout = SystemSessionProperties.getOptimizerTimeout(session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
package com.facebook.presto.sql.planner.iterative;

import com.facebook.presto.sql.planner.plan.PlanNode;
import com.google.common.collect.ImmutableList;

import java.util.List;
import java.util.function.Function;

import static com.google.common.base.Verify.verify;
import static com.google.common.collect.Iterables.getOnlyElement;

public interface Lookup
{
Expand All @@ -28,7 +31,20 @@ public interface Lookup
* If the node is not a GroupReference, it returns the
* argument as is.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update javadoc

PlanNode resolve(PlanNode node);
@Deprecated
default PlanNode resolve(PlanNode node)
{
return getOnlyElement(resolveGroup(node));
}

/**
* Resolves nodes by materializing GroupReference nodes
* representing symbolic references to other nodes.
* <p>
* If the node is not a GroupReference, it returns the
* singleton of the argument node.
*/
List<PlanNode> resolveGroup(PlanNode node);

/**
* A Lookup implementation that does not perform lookup. It satisfies contract
Expand All @@ -38,18 +54,18 @@ static Lookup noLookup()
{
return node -> {
verify(!(node instanceof GroupReference), "Unexpected GroupReference");
return node;
return ImmutableList.of(node);
};
}

static Lookup from(Function<GroupReference, PlanNode> resolver)
static Lookup from(Function<GroupReference, List<PlanNode>> resolver)
{
return node -> {
if (node instanceof GroupReference) {
return resolver.apply((GroupReference) node);
}

return node;
return ImmutableList.of(node);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.facebook.presto.sql.planner.PlanNodeIdAllocator;
import com.facebook.presto.sql.planner.plan.PlanNode;
import com.google.common.collect.ImmutableList;

import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -92,7 +93,7 @@ public PlanNode extract()

private PlanNode extract(PlanNode node)
{
return resolveGroupReferences(node, Lookup.from(this::resolve));
return resolveGroupReferences(node, Lookup.from(planNode -> ImmutableList.of(this.resolve(planNode))));
}

public PlanNode replace(int group, PlanNode node, String reason)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.facebook.presto.sql.planner.plan.PlanNodeId;
import com.facebook.presto.sql.planner.planPrinter.PlanPrinter;
import com.facebook.presto.transaction.TransactionManager;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import java.util.Map;
Expand Down Expand Up @@ -146,7 +147,7 @@ private RuleApplication applyRule()
{
SymbolAllocator symbolAllocator = new SymbolAllocator(symbols);
Memo memo = new Memo(idAllocator, plan);
Lookup lookup = Lookup.from(memo::resolve);
Lookup lookup = Lookup.from(planNode -> ImmutableList.of(memo.resolve(planNode)));

PlanNode memoRoot = memo.getNode(memo.getRootGroup());

Expand Down