Search in sources :

Example 21 with PlanNode

use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.

the class TestEffectivePredicateExtractor method testProject.

@Test
public void testProject() throws Exception {
    PlanNode node = new ProjectNode(newId(), filter(baseTableScan, and(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), Assignments.of(D, AE, E, CE));
    Expression effectivePredicate = EffectivePredicateExtractor.extract(node, TYPES);
    // Rewrite in terms of project output symbols
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(DE, bigintLiteral(10)), equals(DE, EE)));
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) ProjectNode(com.facebook.presto.sql.planner.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 22 with PlanNode

use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.

the class TestEffectivePredicateExtractor method testAggregation.

@Test
public void testAggregation() throws Exception {
    PlanNode node = new AggregationNode(newId(), filter(baseTableScan, and(equals(AE, DE), equals(BE, EE), equals(CE, FE), lessThan(DE, bigintLiteral(10)), lessThan(CE, DE), greaterThan(AE, bigintLiteral(2)), equals(EE, FE))), ImmutableMap.of(C, fakeFunction("test"), D, fakeFunction("test")), ImmutableMap.of(C, fakeFunctionHandle("test", AGGREGATE), D, fakeFunctionHandle("test", AGGREGATE)), ImmutableMap.of(), ImmutableList.of(ImmutableList.of(A, B, C)), AggregationNode.Step.FINAL, Optional.empty(), Optional.empty());
    Expression effectivePredicate = EffectivePredicateExtractor.extract(node, TYPES);
    // Rewrite in terms of group by symbols
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(AE, bigintLiteral(10)), lessThan(BE, AE), greaterThan(AE, bigintLiteral(2)), equals(BE, CE)));
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) AggregationNode(com.facebook.presto.sql.planner.plan.AggregationNode) Test(org.testng.annotations.Test)

Example 23 with PlanNode

use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.

the class PlanMatchingVisitor method matchSources.

/*
     * This is a little counter-intuitive. Calling matchSources calls
     * source.accept, which (eventually) ends up calling into visitPlan
     * recursively. Assuming the plan and pattern currently being matched
     * actually match each other, eventually you hit the leaf nodes. At that
     * point, visitPlan starts by returning the match result for the leaf nodes
     * containing the symbol aliases needed by further up.
     *
     * For the non-leaf nodes, an invocation of matchSources returns a match
     * result for a successful match containing the union of all of the symbol
     * aliases added by the sources of the node currently being visited.
     *
     * Visiting that node proceeds by trying to apply the current pattern's
     * detailMatches() method to the node being visited. When a match is found,
     * visitPlan returns a match result containing the aliases for all of the
     * current node's sources, and the aliases for the current node.
     */
private MatchResult matchSources(PlanNode node, PlanMatchingState state) {
    List<PlanMatchPattern> sourcePatterns = state.getPatterns();
    checkState(node.getSources().size() == sourcePatterns.size(), "Matchers count does not match count of sources");
    int i = 0;
    SymbolAliases.Builder allSourceAliases = SymbolAliases.builder();
    for (PlanNode source : node.getSources()) {
        // Match sources to patterns 1:1
        MatchResult matchResult = source.accept(this, sourcePatterns.get(i++));
        if (!matchResult.isMatch()) {
            return NO_MATCH;
        }
        // Add the per-source aliases to the per-state aliases.
        allSourceAliases.putAll(matchResult.getAliases());
    }
    return match(allSourceAliases.build());
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode)

Example 24 with PlanNode

use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.

the class TestMemo method testReplaceSubtree.

/*
      From: X -> Y  -> Z
      To:   X -> Y' -> Z'
     */
@Test
public void testReplaceSubtree() throws Exception {
    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.sql.planner.plan.PlanNode) Test(org.testng.annotations.Test)

Example 25 with PlanNode

use of com.facebook.presto.sql.planner.plan.PlanNode in project presto by prestodb.

the class TestTypeValidator method testInvalidWindowFunctionSignature.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'sum(_[0-9]+)?' is expected to be double, but the actual type is bigint")
public void testInvalidWindowFunctionSignature() throws Exception {
    Symbol windowSymbol = symbolAllocator.newSymbol("sum", DOUBLE);
    Signature signature = new Signature("sum", FunctionKind.WINDOW, ImmutableList.of(), ImmutableList.of(), // should be DOUBLE
    BIGINT.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()), false);
    FunctionCall functionCall = new FunctionCall(QualifiedName.of("sum"), ImmutableList.of(columnC.toSymbolReference()));
    WindowNode.Frame frame = new WindowNode.Frame(WindowFrame.Type.RANGE, FrameBound.Type.UNBOUNDED_PRECEDING, Optional.empty(), FrameBound.Type.UNBOUNDED_FOLLOWING, Optional.empty());
    WindowNode.Function function = new WindowNode.Function(functionCall, signature, frame);
    WindowNode.Specification specification = new WindowNode.Specification(ImmutableList.of(), ImmutableList.of(), ImmutableMap.of());
    PlanNode node = new WindowNode(newId(), baseTableScan, specification, ImmutableMap.of(windowSymbol, function), Optional.empty(), ImmutableSet.of(), 0);
    assertTypesValid(node);
}
Also used : WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) WindowFrame(com.facebook.presto.sql.tree.WindowFrame) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) Signature(com.facebook.presto.metadata.Signature) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Aggregations

PlanNode (com.facebook.presto.sql.planner.plan.PlanNode)89 Test (org.testng.annotations.Test)41 Expression (com.facebook.presto.sql.tree.Expression)28 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)18 Symbol (com.facebook.presto.sql.planner.Symbol)12 JoinNode (com.facebook.presto.sql.planner.plan.JoinNode)12 ProjectNode (com.facebook.presto.sql.planner.plan.ProjectNode)12 TableScanNode (com.facebook.presto.sql.planner.plan.TableScanNode)12 ImmutableList (com.google.common.collect.ImmutableList)12 AggregationNode (com.facebook.presto.sql.planner.plan.AggregationNode)10 ColumnHandle (com.facebook.presto.spi.ColumnHandle)9 FilterNode (com.facebook.presto.sql.planner.plan.FilterNode)9 LimitNode (com.facebook.presto.sql.planner.plan.LimitNode)9 FunctionCall (com.facebook.presto.sql.tree.FunctionCall)9 Signature (com.facebook.presto.metadata.Signature)7 SemiJoinNode (com.facebook.presto.sql.planner.plan.SemiJoinNode)7 List (java.util.List)7 JoinGraph (com.facebook.presto.sql.planner.optimizations.joins.JoinGraph)6 ValuesNode (com.facebook.presto.sql.planner.plan.ValuesNode)6 Session (com.facebook.presto.Session)5