private PlanNodeCostEstimate calculateCumulativeCost(PlanNode node) { PlanNodeCostEstimate localCosts = costCalculator.calculateCost(node, statsProvider, session, types); PlanNodeCostEstimate sourcesCost = node.getSources().stream() .map(this::getCumulativeCost) .reduce(PlanNodeCostEstimate.zero(), PlanNodeCostEstimate::add); PlanNodeCostEstimate cumulativeCost = localCosts.add(sourcesCost); return cumulativeCost; } }
@Override public PlanNodeCostEstimate calculateCost(PlanNode node, StatsProvider stats, Session session, TypeProvider types) { ExchangeCostEstimator exchangeCostEstimator = new ExchangeCostEstimator(stats, types, taskCountEstimator); PlanNodeCostEstimate estimatedExchangeCost = node.accept(exchangeCostEstimator, null); return costCalculator.calculateCost(node, stats, session, types).add(estimatedExchangeCost); }
private PlanNodeCostEstimate calculateCumulativeCost(PlanNode node) { PlanNodeCostEstimate sourcesCost = node.getSources().stream() .map(this::getCumulativeCost) .reduce(PlanNodeCostEstimate.zero(), PlanNodeCostEstimate::add); return costCalculator.calculateCost(node, statsProvider, session, types).add(sourcesCost); } }
private PlanNodeCostEstimate calculateCumulativeCost( CostCalculator costCalculator, PlanNode node, Function<PlanNode, PlanNodeCostEstimate> costs, Function<PlanNode, PlanNodeStatsEstimate> stats, Map<String, Type> types) { PlanNodeCostEstimate localCost = costCalculator.calculateCost( node, planNode -> requireNonNull(stats.apply(planNode), "no stats for node"), session, TypeProvider.copyOf(types.entrySet().stream() .collect(ImmutableMap.toImmutableMap(entry -> new Symbol(entry.getKey()), Map.Entry::getValue)))); PlanNodeCostEstimate sourcesCost = node.getSources().stream() .map(source -> requireNonNull(costs.apply(source), format("no cost for source: %s", source.getId()))) .reduce(PlanNodeCostEstimate.zero(), PlanNodeCostEstimate::add); return sourcesCost.add(localCost); }