Search in sources :

Example 1 with PlanCostEstimate

use of com.facebook.presto.cost.PlanCostEstimate 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 2 with PlanCostEstimate

use of com.facebook.presto.cost.PlanCostEstimate in project presto by prestodb.

the class TextRenderer method printEstimates.

private String printEstimates(PlanRepresentation plan, NodeRepresentation node) {
    if (node.getEstimatedStats().stream().allMatch(PlanNodeStatsEstimate::isOutputRowCountUnknown) && node.getEstimatedCost().stream().allMatch(c -> c.equals(PlanCostEstimate.unknown()))) {
        return "";
    }
    StringBuilder output = new StringBuilder();
    int estimateCount = node.getEstimatedStats().size();
    output.append("Estimates: ");
    for (int i = 0; i < estimateCount; i++) {
        PlanNodeStatsEstimate stats = node.getEstimatedStats().get(i);
        PlanCostEstimate cost = node.getEstimatedCost().get(i);
        output.append(format("{rows: %s (%s), cpu: %s, memory: %s, network: %s}", formatAsLong(stats.getOutputRowCount()), formatEstimateAsDataSize(stats.getOutputSizeInBytes(node.getOutputs())), formatDouble(cost.getCpuCost()), formatDouble(cost.getMaxMemory()), formatDouble(cost.getNetworkCost())));
        if (i < estimateCount - 1) {
            output.append("/");
        }
    }
    output.append("\n");
    return output.toString();
}
Also used : Collections.emptyMap(java.util.Collections.emptyMap) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) DataSize.succinctBytes(io.airlift.units.DataSize.succinctBytes) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) PlanCostEstimate(com.facebook.presto.cost.PlanCostEstimate) Strings(com.google.common.base.Strings) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Double.isNaN(java.lang.Double.isNaN) Locale(java.util.Locale) Map(java.util.Map) Optional(java.util.Optional) Double.isFinite(java.lang.Double.isFinite) PlanCostEstimate(com.facebook.presto.cost.PlanCostEstimate) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate)

Aggregations

PlanCostEstimate (com.facebook.presto.cost.PlanCostEstimate)2 PlanNodeStatsEstimate (com.facebook.presto.cost.PlanNodeStatsEstimate)1 PlanNode (com.facebook.presto.spi.plan.PlanNode)1 Strings (com.google.common.base.Strings)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 DataSize.succinctBytes (io.airlift.units.DataSize.succinctBytes)1 Double.isFinite (java.lang.Double.isFinite)1 Double.isNaN (java.lang.Double.isNaN)1 String.format (java.lang.String.format)1 Collections.emptyMap (java.util.Collections.emptyMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors.joining (java.util.stream.Collectors.joining)1 Collectors.toList (java.util.stream.Collectors.toList)1 Test (org.testng.annotations.Test)1