Search in sources :

Example 51 with PlanNode

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

the class TestTypeValidator method testInvalidUnion.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of variable 'output(_[0-9]+)?' is expected to be date, but the actual type is bigint")
public void testInvalidUnion() {
    VariableReferenceExpression output = variableAllocator.newVariable("output", DATE);
    PlanNode node = new UnionNode(Optional.empty(), newId(), ImmutableList.of(baseTableScan, baseTableScan), ImmutableList.of(output), ImmutableMap.of(output, ImmutableList.of(variableD, // should be a symbol with DATE type
    variableA)));
    assertTypesValid(node);
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) UnionNode(com.facebook.presto.spi.plan.UnionNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test)

Example 52 with PlanNode

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

the class TestTypeValidator method testInvalidWindowFunctionSignature.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of variable 'sum(_[0-9]+)?' is expected to be double, but the actual type is bigint")
public void testInvalidWindowFunctionSignature() {
    VariableReferenceExpression windowVariable = variableAllocator.newVariable("sum", DOUBLE);
    // should be DOUBLE
    FunctionHandle functionHandle = FUNCTION_MANAGER.lookupFunction("sum", fromTypes(BIGINT));
    WindowNode.Frame frame = new WindowNode.Frame(RANGE, UNBOUNDED_PRECEDING, Optional.empty(), UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty(), Optional.empty());
    WindowNode.Function function = new WindowNode.Function(call("sum", functionHandle, BIGINT, variableC), frame, false);
    WindowNode.Specification specification = new WindowNode.Specification(ImmutableList.of(), Optional.empty());
    PlanNode node = new WindowNode(Optional.empty(), newId(), baseTableScan, specification, ImmutableMap.of(windowVariable, function), Optional.empty(), ImmutableSet.of(), 0);
    assertTypesValid(node);
}
Also used : WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) PlanNode(com.facebook.presto.spi.plan.PlanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) Test(org.testng.annotations.Test)

Example 53 with PlanNode

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

the class TestTypeValidator method testValidAggregation.

@Test
public void testValidAggregation() {
    VariableReferenceExpression aggregationVariable = variableAllocator.newVariable("sum", DOUBLE);
    PlanNode node = new AggregationNode(Optional.empty(), newId(), baseTableScan, ImmutableMap.of(aggregationVariable, new Aggregation(new CallExpression("sum", SUM, DOUBLE, ImmutableList.of(variableC)), Optional.empty(), Optional.empty(), false, Optional.empty())), singleGroupingSet(ImmutableList.of(variableA, variableB)), ImmutableList.of(), SINGLE, Optional.empty(), Optional.empty());
    assertTypesValid(node);
}
Also used : Aggregation(com.facebook.presto.spi.plan.AggregationNode.Aggregation) PlanNode(com.facebook.presto.spi.plan.PlanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) CallExpression(com.facebook.presto.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Example 54 with PlanNode

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

the class TestEffectivePredicateExtractor method testAggregation.

@Test
public void testAggregation() {
    PlanNode node = new AggregationNode(Optional.empty(), newId(), filter(baseTableScan, and(equals(AV, DV), equals(BV, EV), equals(CV, FV), lessThan(DV, bigintLiteral(10)), lessThan(CV, DV), greaterThan(AV, bigintLiteral(2)), equals(EV, FV))), ImmutableMap.of(CV, count(metadata.getFunctionAndTypeManager()), DV, count(metadata.getFunctionAndTypeManager())), singleGroupingSet(ImmutableList.of(AV, BV, CV)), ImmutableList.of(), AggregationNode.Step.FINAL, Optional.empty(), Optional.empty());
    RowExpression effectivePredicate = effectivePredicateExtractor.extract(node);
    // Rewrite in terms of group by symbols
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(AV, bigintLiteral(10)), lessThan(BV, AV), greaterThan(AV, bigintLiteral(2)), equals(BV, CV)));
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) RowExpression(com.facebook.presto.spi.relation.RowExpression) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) Test(org.testng.annotations.Test)

Example 55 with PlanNode

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

the class TestEffectivePredicateExtractor method testWindow.

@Test
public void testWindow() {
    PlanNode node = new WindowNode(Optional.empty(), newId(), filter(baseTableScan, and(equals(AV, BV), equals(BV, CV), lessThan(CV, bigintLiteral(10)))), new WindowNode.Specification(ImmutableList.of(AV), Optional.of(new OrderingScheme(ImmutableList.of(new Ordering(AV, SortOrder.ASC_NULLS_LAST))))), ImmutableMap.of(), Optional.empty(), ImmutableSet.of(), 0);
    RowExpression effectivePredicate = effectivePredicateExtractor.extract(node);
    // Pass through
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(AV, BV), equals(BV, CV), lessThan(CV, bigintLiteral(10))));
}
Also used : WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) OrderingScheme(com.facebook.presto.spi.plan.OrderingScheme) PlanNode(com.facebook.presto.spi.plan.PlanNode) Ordering(com.facebook.presto.spi.plan.Ordering) RowExpression(com.facebook.presto.spi.relation.RowExpression) 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