Search in sources :

Example 86 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)

Example 87 with PlanNode

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

the class TestTypeValidator method testValidTypeOnlyCoercion.

@Test
public void testValidTypeOnlyCoercion() throws Exception {
    Expression expression = new Cast(columnB.toSymbolReference(), StandardTypes.BIGINT);
    Assignments assignments = Assignments.builder().put(symbolAllocator.newSymbol(expression, BIGINT), expression).put(symbolAllocator.newSymbol(columnE.toSymbolReference(), VARCHAR), // implicit coercion from varchar(3) to varchar
    columnE.toSymbolReference()).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 88 with PlanNode

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

the class TestTypeValidator method testInvalidWindowFunctionCall.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'sum(_[0-9]+)?' is expected to be double, but the actual type is bigint")
public void testInvalidWindowFunctionCall() throws Exception {
    Symbol windowSymbol = symbolAllocator.newSymbol("sum", DOUBLE);
    Signature signature = new Signature("sum", FunctionKind.WINDOW, ImmutableList.of(), ImmutableList.of(), DOUBLE.getTypeSignature(), ImmutableList.of(DOUBLE.getTypeSignature()), false);
    // should be columnC
    FunctionCall functionCall = new FunctionCall(QualifiedName.of("sum"), ImmutableList.of(columnA.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)

Example 89 with PlanNode

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

the class TestTypeValidator method testValidWindow.

@Test
public void testValidWindow() throws Exception {
    Symbol windowSymbol = symbolAllocator.newSymbol("sum", DOUBLE);
    Signature signature = new Signature("sum", FunctionKind.WINDOW, ImmutableList.of(), ImmutableList.of(), DOUBLE.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