use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class TableWriterMatcher method detailMatches.
@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
TableWriterNode tableWriterNode = (TableWriterNode) node;
if (!tableWriterNode.getColumnNames().equals(columnNames)) {
return NO_MATCH;
}
if (!columns.stream().map(s -> Symbol.from(symbolAliases.get(s))).collect(toImmutableList()).equals(tableWriterNode.getColumns().stream().map(VariableReferenceExpression::getName).map(Symbol::new).collect(toImmutableList()))) {
return NO_MATCH;
}
return match();
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class WindowMatcher method detailMatches.
@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
WindowNode windowNode = (WindowNode) node;
if (!prePartitionedInputs.map(expectedInputs -> expectedInputs.stream().map(alias -> alias.toSymbol(symbolAliases)).collect(toImmutableSet()).equals(windowNode.getPrePartitionedInputs().stream().map(VariableReferenceExpression::getName).map(Symbol::new).collect(toImmutableSet()))).orElse(true)) {
return NO_MATCH;
}
if (!specification.map(expectedSpecification -> matchSpecification(windowNode.getSpecification(), expectedSpecification.getExpectedValue(symbolAliases))).orElse(true)) {
return NO_MATCH;
}
if (!preSortedOrderPrefix.map(Integer.valueOf(windowNode.getPreSortedOrderPrefix())::equals).orElse(true)) {
return NO_MATCH;
}
if (!hashSymbol.map(expectedHashSymbol -> expectedHashSymbol.map(alias -> alias.toSymbol(symbolAliases)).map(Symbol::getName).equals(windowNode.getHashVariable().map(VariableReferenceExpression::getName))).orElse(true)) {
return NO_MATCH;
}
/*
* Window functions produce a symbol (the result of the function call) that we might
* want to bind to an alias so we can reference it further up the tree. As such,
* they need to be matched with an Alias matcher so we can bind the symbol if desired.
*/
return match();
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class TestMemo method testReplaceNode.
/*
From: X -> Y -> Z
To: X -> Y' -> Z
*/
@Test
public void testReplaceNode() {
PlanNode z = node();
PlanNode y = node(z);
PlanNode x = node(y);
Memo memo = new Memo(idAllocator, x);
assertEquals(memo.getGroupCount(), 3);
// replace child of root node with another node, retaining child's child
int yGroup = getChildGroup(memo, memo.getRootGroup());
GroupReference zRef = (GroupReference) getOnlyElement(memo.getNode(yGroup).getSources());
PlanNode transformed = node(zRef);
memo.replace(yGroup, transformed, "rule");
assertEquals(memo.getGroupCount(), 3);
assertMatchesStructure(memo.extract(), node(x.getId(), node(transformed.getId(), z)));
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class PlanMatchingVisitor method matchSources.
/*
* This is a little counter-intuitive. Calling matchSources calls
* source.accept, which (eventually) ends up calling into visitPlan
* recursively. Assuming the plan and pattern currently being matched
* actually match each other, eventually you hit the leaf nodes. At that
* point, visitPlan starts by returning the match result for the leaf nodes
* containing the symbol aliases needed by further up.
*
* For the non-leaf nodes, an invocation of matchSources returns a match
* result for a successful match containing the union of all of the symbol
* aliases added by the sources of the node currently being visited.
*
* Visiting that node proceeds by trying to apply the current pattern's
* detailMatches() method to the node being visited. When a match is found,
* visitPlan returns a match result containing the aliases for all of the
* current node's sources, and the aliases for the current node.
*/
private MatchResult matchSources(PlanNode node, PlanMatchingState state) {
List<PlanMatchPattern> sourcePatterns = state.getPatterns();
checkState(node.getSources().size() == sourcePatterns.size(), "Matchers count does not match count of sources");
int i = 0;
SymbolAliases.Builder allSourceAliases = SymbolAliases.builder();
for (PlanNode source : node.getSources()) {
// Match sources to patterns 1:1
MatchResult matchResult = source.accept(this, sourcePatterns.get(i++));
if (!matchResult.isMatch()) {
return NO_MATCH;
}
// Add the per-source aliases to the per-state aliases.
allSourceAliases.putAll(matchResult.getAliases());
}
return match(allSourceAliases.build());
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class RowNumberMatcher method detailMatches.
@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
RowNumberNode rowNumberNode = (RowNumberNode) node;
if (!partitionBy.map(expectedPartitionBy -> expectedPartitionBy.stream().map(alias -> alias.toSymbol(symbolAliases)).map(Symbol::getName).collect(toImmutableList()).equals(rowNumberNode.getPartitionBy().stream().map(VariableReferenceExpression::getName).collect(toImmutableList()))).orElse(true)) {
return NO_MATCH;
}
if (!maxRowCountPerPartition.map(expectedMaxRowCountPerPartition -> expectedMaxRowCountPerPartition.equals(rowNumberNode.getMaxRowCountPerPartition())).orElse(true)) {
return NO_MATCH;
}
if (!rowNumberSymbol.map(expectedRowNumberSymbol -> expectedRowNumberSymbol.toSymbol(symbolAliases).getName().equals(rowNumberNode.getRowNumberVariable().getName())).orElse(true)) {
return NO_MATCH;
}
if (!hashSymbol.map(expectedHashSymbol -> expectedHashSymbol.map(symbolAlias -> symbolAlias.toSymbol(symbolAliases)).map(Symbol::getName).equals(rowNumberNode.getHashVariable().map(VariableReferenceExpression::getName))).orElse(true)) {
return NO_MATCH;
}
return match();
}
Aggregations