Search in sources :

Example 81 with PlanNode

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()))));
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) Test(org.testng.annotations.Test)

Example 82 with PlanNode

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());
}
Also used : PlanCostEstimate(com.facebook.presto.cost.PlanCostEstimate) PlanNode(com.facebook.presto.spi.plan.PlanNode) Test(org.testng.annotations.Test)

Example 83 with PlanNode

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())))));
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) Test(org.testng.annotations.Test)

Example 84 with PlanNode

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());
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate) Test(org.testng.annotations.Test)

Example 85 with PlanNode

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));
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) Test(org.testng.annotations.Test)

Aggregations

PlanNode (com.facebook.presto.spi.plan.PlanNode)228 Test (org.testng.annotations.Test)114 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)94 ImmutableList (com.google.common.collect.ImmutableList)56 RowExpression (com.facebook.presto.spi.relation.RowExpression)45 ImmutableMap (com.google.common.collect.ImmutableMap)44 PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)42 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)41 AggregationNode (com.facebook.presto.spi.plan.AggregationNode)40 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)40 Map (java.util.Map)39 Optional (java.util.Optional)38 List (java.util.List)36 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)35 Set (java.util.Set)30 Assert.assertEquals (org.testng.Assert.assertEquals)23 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)22 OrderingScheme (com.facebook.presto.spi.plan.OrderingScheme)20 Function (java.util.function.Function)20 Metadata (com.facebook.presto.metadata.Metadata)19