Search in sources :

Example 71 with PlanNode

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

the class TestEffectivePredicateExtractor method testSort.

@Test
public void testSort() throws Exception {
    PlanNode node = new SortNode(newId(), filter(baseTableScan, and(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), ImmutableList.of(A), ImmutableMap.of(A, SortOrder.ASC_NULLS_LAST));
    Expression effectivePredicate = EffectivePredicateExtractor.extract(node, TYPES);
    // Pass through
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10))));
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) SortNode(com.facebook.presto.sql.planner.plan.SortNode) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) Test(org.testng.annotations.Test)

Example 72 with PlanNode

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

the class TestEffectivePredicateExtractor method testTopN.

@Test
public void testTopN() throws Exception {
    PlanNode node = new TopNNode(newId(), filter(baseTableScan, and(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10)))), 1, ImmutableList.of(A), ImmutableMap.of(A, SortOrder.ASC_NULLS_LAST), true);
    Expression effectivePredicate = EffectivePredicateExtractor.extract(node, TYPES);
    // Pass through
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(AE, BE), equals(BE, CE), lessThan(CE, bigintLiteral(10))));
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) TopNNode(com.facebook.presto.sql.planner.plan.TopNNode) Test(org.testng.annotations.Test)

Example 73 with PlanNode

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

the class TestTypeValidator method testInvalidProject.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'expr(_[0-9]+)?' is expected to be bigint, but the actual type is integer")
public void testInvalidProject() throws Exception {
    Expression expression1 = new Cast(columnB.toSymbolReference(), StandardTypes.INTEGER);
    Expression expression2 = new Cast(columnA.toSymbolReference(), StandardTypes.INTEGER);
    Assignments assignments = Assignments.builder().put(symbolAllocator.newSymbol(expression1, BIGINT), // should be INTEGER
    expression1).put(symbolAllocator.newSymbol(expression1, INTEGER), expression2).build();
    PlanNode node = new ProjectNode(newId(), baseTableScan, assignments);
    assertTypesValid(node);
}
Also used : Cast(com.facebook.presto.sql.tree.Cast) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) Expression(com.facebook.presto.sql.tree.Expression) Assignments(com.facebook.presto.sql.planner.plan.Assignments) ProjectNode(com.facebook.presto.sql.planner.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 74 with PlanNode

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

the class TestTypeValidator method testInvalidAggregationFunctionSignature.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'sum(_[0-9]+)?' is expected to be double, but the actual type is bigint")
public void testInvalidAggregationFunctionSignature() throws Exception {
    Symbol aggregationSymbol = symbolAllocator.newSymbol("sum", DOUBLE);
    Map<Symbol, Signature> functions = ImmutableMap.of(aggregationSymbol, new Signature("sum", FunctionKind.AGGREGATE, ImmutableList.of(), ImmutableList.of(), // should be DOUBLE
    BIGINT.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()), false));
    Map<Symbol, FunctionCall> aggregations = ImmutableMap.of(aggregationSymbol, new FunctionCall(QualifiedName.of("sum"), ImmutableList.of(columnC.toSymbolReference())));
    PlanNode node = new AggregationNode(newId(), baseTableScan, aggregations, functions, ImmutableMap.of(), ImmutableList.of(ImmutableList.of(columnA, columnB)), SINGLE, Optional.empty(), Optional.empty());
    assertTypesValid(node);
}
Also used : PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) Signature(com.facebook.presto.metadata.Signature) AggregationNode(com.facebook.presto.sql.planner.plan.AggregationNode) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 75 with PlanNode

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

the class TestTypeValidator method testValidProject.

@Test
public void testValidProject() throws Exception {
    Expression expression1 = new Cast(columnB.toSymbolReference(), StandardTypes.BIGINT);
    Expression expression2 = new Cast(columnC.toSymbolReference(), StandardTypes.BIGINT);
    Assignments assignments = Assignments.builder().put(symbolAllocator.newSymbol(expression1, BIGINT), expression1).put(symbolAllocator.newSymbol(expression2, BIGINT), expression2).build();
    PlanNode node = new ProjectNode(newId(), baseTableScan, assignments);
    assertTypesValid(node);
}
Also used : Cast(com.facebook.presto.sql.tree.Cast) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) Expression(com.facebook.presto.sql.tree.Expression) Assignments(com.facebook.presto.sql.planner.plan.Assignments) ProjectNode(com.facebook.presto.sql.planner.plan.ProjectNode) 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