use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class TestMemo method testMultipleReferences.
/*
From: X -> Y -> Z
To: X --> Y1' --> Z
\-> Y2' -/
*/
@Test
public void testMultipleReferences() {
PlanNode z = node();
PlanNode y = node(z);
PlanNode x = node(y);
Memo memo = new Memo(idAllocator, x);
assertEquals(memo.getGroupCount(), 3);
int yGroup = getChildGroup(memo, memo.getRootGroup());
PlanNode rewrittenZ = memo.getNode(yGroup).getSources().get(0);
PlanNode y1 = node(rewrittenZ);
PlanNode y2 = node(rewrittenZ);
PlanNode newX = node(y1, y2);
memo.replace(memo.getRootGroup(), newX, "rule");
assertEquals(memo.getGroupCount(), 4);
assertMatchesStructure(memo.extract(), node(newX.getId(), node(y1.getId(), node(z.getId())), node(y2.getId(), node(z.getId()))));
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class TestMemo method testEvictCostOnReplace.
@Test
public void testEvictCostOnReplace() {
PlanNode y = node();
PlanNode x = node(y);
Memo memo = new Memo(idAllocator, x);
int xGroup = memo.getRootGroup();
int yGroup = getChildGroup(memo, memo.getRootGroup());
PlanCostEstimate yCost = new PlanCostEstimate(42, 0, 0, 0);
PlanCostEstimate xCost = new PlanCostEstimate(42, 0, 0, 37);
memo.storeCost(yGroup, yCost);
memo.storeCost(xGroup, xCost);
assertEquals(memo.getCost(yGroup), Optional.of(yCost));
assertEquals(memo.getCost(xGroup), Optional.of(xCost));
memo.replace(yGroup, node(), "rule");
assertEquals(memo.getCost(yGroup), Optional.empty());
assertEquals(memo.getCost(xGroup), Optional.empty());
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class TestMemo method testReplaceNonLeafSubtree.
/*
From: X -> Y -> Z -> W
To: X -> Y' -> Z' -> W
*/
@Test
public void testReplaceNonLeafSubtree() {
PlanNode w = node();
PlanNode z = node(w);
PlanNode y = node(z);
PlanNode x = node(y);
Memo memo = new Memo(idAllocator, x);
assertEquals(memo.getGroupCount(), 4);
int yGroup = getChildGroup(memo, memo.getRootGroup());
int zGroup = getChildGroup(memo, yGroup);
PlanNode rewrittenW = memo.getNode(zGroup).getSources().get(0);
PlanNode newZ = node(rewrittenW);
PlanNode newY = node(newZ);
memo.replace(yGroup, newY, "rule");
assertEquals(memo.getGroupCount(), 4);
assertMatchesStructure(memo.extract(), node(x.getId(), node(newY.getId(), node(newZ.getId(), node(w.getId())))));
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class TestMemo method testEvictStatsOnReplace.
@Test
public void testEvictStatsOnReplace() {
PlanNode y = node();
PlanNode x = node(y);
Memo memo = new Memo(idAllocator, x);
int xGroup = memo.getRootGroup();
int yGroup = getChildGroup(memo, memo.getRootGroup());
PlanNodeStatsEstimate xStats = PlanNodeStatsEstimate.builder().setOutputRowCount(42).build();
PlanNodeStatsEstimate yStats = PlanNodeStatsEstimate.builder().setOutputRowCount(55).build();
memo.storeStats(yGroup, yStats);
memo.storeStats(xGroup, xStats);
assertEquals(memo.getStats(yGroup), Optional.of(yStats));
assertEquals(memo.getStats(xGroup), Optional.of(xStats));
memo.replace(yGroup, node(), "rule");
assertEquals(memo.getStats(yGroup), Optional.empty());
assertEquals(memo.getStats(xGroup), Optional.empty());
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class TestMemo method testReplaceSubtree.
/*
From: X -> Y -> Z
To: X -> Y' -> Z'
*/
@Test
public void testReplaceSubtree() {
PlanNode plan = node(node(node()));
Memo memo = new Memo(idAllocator, plan);
assertEquals(memo.getGroupCount(), 3);
// replace child of root node with subtree
PlanNode transformed = node(node());
memo.replace(getChildGroup(memo, memo.getRootGroup()), transformed, "rule");
assertEquals(memo.getGroupCount(), 3);
assertMatchesStructure(memo.extract(), node(plan.getId(), transformed));
}
Aggregations