Search in sources :

Example 6 with WindowNode

use of com.facebook.presto.sql.planner.plan.WindowNode 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 7 with WindowNode

use of com.facebook.presto.sql.planner.plan.WindowNode 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

WindowNode (com.facebook.presto.sql.planner.plan.WindowNode)7 FunctionCall (com.facebook.presto.sql.tree.FunctionCall)5 PlanNode (com.facebook.presto.sql.planner.plan.PlanNode)4 WindowFrame (com.facebook.presto.sql.tree.WindowFrame)4 Test (org.testng.annotations.Test)4 Signature (com.facebook.presto.metadata.Signature)3 Expression (com.facebook.presto.sql.tree.Expression)2 SortOrder (com.facebook.presto.spi.block.SortOrder)1 Symbol (com.facebook.presto.sql.planner.Symbol)1 Cast (com.facebook.presto.sql.tree.Cast)1 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)1 FrameBound (com.facebook.presto.sql.tree.FrameBound)1 SortItem (com.facebook.presto.sql.tree.SortItem)1 SymbolReference (com.facebook.presto.sql.tree.SymbolReference)1 Window (com.facebook.presto.sql.tree.Window)1 IdentityLinkedHashMap (com.facebook.presto.util.maps.IdentityLinkedHashMap)1 ImmutableList (com.google.common.collect.ImmutableList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1