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);
}
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);
}
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);
}
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);
}
Aggregations