use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class UnionStatsRule method doCalculate.
@Override
protected final Optional<PlanNodeStatsEstimate> doCalculate(UnionNode node, StatsProvider statsProvider, Lookup lookup, Session session, TypeProvider types) {
checkArgument(!node.getSources().isEmpty(), "Empty Union is not supported");
Optional<PlanNodeStatsEstimate> estimate = Optional.empty();
for (int i = 0; i < node.getSources().size(); i++) {
PlanNode source = node.getSources().get(i);
PlanNodeStatsEstimate sourceStats = statsProvider.getStats(source);
PlanNodeStatsEstimate sourceStatsWithMappedSymbols = mapToOutputSymbols(sourceStats, node, i);
if (estimate.isPresent()) {
estimate = Optional.of(addStatsAndCollapseDistinctValues(estimate.get(), sourceStatsWithMappedSymbols));
} else {
estimate = Optional.of(sourceStatsWithMappedSymbols);
}
}
return estimate;
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class StatsAndCosts method getForSubplan.
public StatsAndCosts getForSubplan(PlanNode root) {
Iterable<PlanNode> planIterator = Traverser.forTree(PlanNode::getSources).depthFirstPreOrder(root);
ImmutableMap.Builder<PlanNodeId, PlanNodeStatsEstimate> filteredStats = ImmutableMap.builder();
ImmutableMap.Builder<PlanNodeId, PlanCostEstimate> filteredCosts = ImmutableMap.builder();
for (PlanNode node : planIterator) {
if (stats.containsKey(node.getId())) {
filteredStats.put(node.getId(), stats.get(node.getId()));
}
if (costs.containsKey(node.getId())) {
filteredCosts.put(node.getId(), costs.get(node.getId()));
}
}
return new StatsAndCosts(filteredStats.build(), filteredCosts.build());
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class SimpleFilterProjectSemiJoinStatsRule method doCalculate.
@Override
protected Optional<PlanNodeStatsEstimate> doCalculate(FilterNode node, StatsProvider sourceStats, Lookup lookup, Session session, TypeProvider types) {
PlanNode nodeSource = lookup.resolve(node.getSource());
SemiJoinNode semiJoinNode;
if (nodeSource instanceof ProjectNode) {
ProjectNode projectNode = (ProjectNode) nodeSource;
if (!isIdentity(projectNode)) {
return Optional.empty();
}
PlanNode projectNodeSource = lookup.resolve(projectNode.getSource());
if (!(projectNodeSource instanceof SemiJoinNode)) {
return Optional.empty();
}
semiJoinNode = (SemiJoinNode) projectNodeSource;
} else if (nodeSource instanceof SemiJoinNode) {
semiJoinNode = (SemiJoinNode) nodeSource;
} else {
return Optional.empty();
}
return calculate(node, semiJoinNode, sourceStats, session, types);
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class RuleAssert method applyRule.
private RuleApplication applyRule() {
PlanVariableAllocator variableAllocator = new PlanVariableAllocator(types.allVariables());
Memo memo = new Memo(idAllocator, plan);
Lookup lookup = Lookup.from(planNode -> Stream.of(memo.resolve(planNode)));
PlanNode memoRoot = memo.getNode(memo.getRootGroup());
return inTransaction(session -> applyRule(rule, memoRoot, ruleContext(statsCalculator, costCalculator, variableAllocator, memo, lookup, session)));
}
use of com.facebook.presto.spi.plan.PlanNode in project presto by prestodb.
the class TestConnectorOptimization method testPushFilterToTableScan.
@Test
public void testPushFilterToTableScan() {
RowExpression expectedPredicate = and(newBigintVariable("a"), newBigintVariable("b"));
PlanNode plan = output(filter(tableScan("cat1", "a", "b"), expectedPredicate), "a");
PlanNode actual = optimize(plan, ImmutableMap.of(new ConnectorId("cat1"), ImmutableSet.of(filterPushdown())));
// assert structure; FilterNode is removed
assertPlanMatch(actual, PlanMatchPattern.output(SimpleTableScanMatcher.tableScan("cat1", expectedPredicate)));
}
Aggregations