Search in sources :

Example 91 with PlanNode

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

Example 92 with PlanNode

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());
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PlanNode(com.facebook.presto.spi.plan.PlanNode) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 93 with PlanNode

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);
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) ProjectNode(com.facebook.presto.spi.plan.ProjectNode) SemiJoinNode(com.facebook.presto.sql.planner.plan.SemiJoinNode)

Example 94 with PlanNode

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)));
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) Lookup(com.facebook.presto.sql.planner.iterative.Lookup) PlanVariableAllocator(com.facebook.presto.sql.planner.PlanVariableAllocator) Memo(com.facebook.presto.sql.planner.iterative.Memo)

Example 95 with PlanNode

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)));
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) RowExpression(com.facebook.presto.spi.relation.RowExpression) ConnectorId(com.facebook.presto.spi.ConnectorId) 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