Search in sources :

Example 31 with FunctionCall

use of com.facebook.presto.sql.tree.FunctionCall in project presto by prestodb.

the class TestSqlParser method testPosition.

@Test
public void testPosition() throws Exception {
    assertExpression("position('a' in 'b')", new FunctionCall(QualifiedName.of("strpos"), ImmutableList.of(new StringLiteral("b"), new StringLiteral("a"))));
    assertExpression("position('a' in ('b'))", new FunctionCall(QualifiedName.of("strpos"), ImmutableList.of(new StringLiteral("b"), new StringLiteral("a"))));
}
Also used : StringLiteral(com.facebook.presto.sql.tree.StringLiteral) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 32 with FunctionCall

use of com.facebook.presto.sql.tree.FunctionCall in project presto by prestodb.

the class TestSqlParser method testSetSession.

@Test
public void testSetSession() throws Exception {
    assertStatement("SET SESSION foo = 'bar'", new SetSession(QualifiedName.of("foo"), new StringLiteral("bar")));
    assertStatement("SET SESSION foo.bar = 'baz'", new SetSession(QualifiedName.of("foo", "bar"), new StringLiteral("baz")));
    assertStatement("SET SESSION foo.bar.boo = 'baz'", new SetSession(QualifiedName.of("foo", "bar", "boo"), new StringLiteral("baz")));
    assertStatement("SET SESSION foo.bar = 'ban' || 'ana'", new SetSession(QualifiedName.of("foo", "bar"), new FunctionCall(QualifiedName.of("concat"), ImmutableList.of(new StringLiteral("ban"), new StringLiteral("ana")))));
}
Also used : SetSession(com.facebook.presto.sql.tree.SetSession) StringLiteral(com.facebook.presto.sql.tree.StringLiteral) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 33 with FunctionCall

use of com.facebook.presto.sql.tree.FunctionCall in project presto by prestodb.

the class TestWindowNode method testSerializationRoundtrip.

@Test
public void testSerializationRoundtrip() throws Exception {
    Symbol windowSymbol = symbolAllocator.newSymbol("sum", BIGINT);
    Signature signature = new Signature("sum", FunctionKind.WINDOW, ImmutableList.of(), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(BIGINT.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());
    PlanNodeId id = newId();
    WindowNode.Specification specification = new WindowNode.Specification(ImmutableList.of(columnA), ImmutableList.of(columnB), ImmutableMap.of(columnB, SortOrder.ASC_NULLS_FIRST));
    Map<Symbol, WindowNode.Function> functions = ImmutableMap.of(windowSymbol, new WindowNode.Function(functionCall, signature, frame));
    Optional<Symbol> hashSymbol = Optional.of(columnB);
    Set<Symbol> prePartitionedInputs = ImmutableSet.of(columnA);
    WindowNode windowNode = new WindowNode(id, sourceNode, specification, functions, hashSymbol, prePartitionedInputs, 0);
    String json = objectMapper.writeValueAsString(windowNode);
    WindowNode actualNode = objectMapper.readValue(json, WindowNode.class);
    assertEquals(actualNode.getId(), windowNode.getId());
    assertEquals(actualNode.getSpecification(), windowNode.getSpecification());
    assertEquals(actualNode.getWindowFunctions(), windowNode.getWindowFunctions());
    assertEquals(actualNode.getFrames(), windowNode.getFrames());
    assertEquals(actualNode.getHashSymbol(), windowNode.getHashSymbol());
    assertEquals(actualNode.getPrePartitionedInputs(), windowNode.getPrePartitionedInputs());
    assertEquals(actualNode.getPreSortedOrderPrefix(), windowNode.getPreSortedOrderPrefix());
}
Also used : WindowFrame(com.facebook.presto.sql.tree.WindowFrame) Symbol(com.facebook.presto.sql.planner.Symbol) Signature(com.facebook.presto.metadata.Signature) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) Test(org.testng.annotations.Test)

Example 34 with FunctionCall

use of com.facebook.presto.sql.tree.FunctionCall in project presto by prestodb.

the class WindowFunctionMatcher method getAssignedSymbol.

@Override
public Optional<Symbol> getAssignedSymbol(PlanNode node, Session session, Metadata metadata, SymbolAliases symbolAliases) {
    Optional<Symbol> result = Optional.empty();
    if (!(node instanceof WindowNode)) {
        return result;
    }
    WindowNode windowNode = (WindowNode) node;
    FunctionCall expectedCall = callMaker.getExpectedValue(symbolAliases);
    for (Map.Entry<Symbol, WindowNode.Function> assignment : windowNode.getWindowFunctions().entrySet()) {
        if (expectedCall.equals(assignment.getValue().getFunctionCall())) {
            checkState(!result.isPresent(), "Ambiguous function calls in %s", windowNode);
            result = Optional.of(assignment.getKey());
        }
    }
    return result;
}
Also used : WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) Symbol(com.facebook.presto.sql.planner.Symbol) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) Map(java.util.Map)

Aggregations

FunctionCall (com.facebook.presto.sql.tree.FunctionCall)34 Test (org.testng.annotations.Test)19 Expression (com.facebook.presto.sql.tree.Expression)13 Signature (com.facebook.presto.metadata.Signature)11 StringLiteral (com.facebook.presto.sql.tree.StringLiteral)11 AggregationNode (com.facebook.presto.sql.planner.plan.AggregationNode)9 PlanNode (com.facebook.presto.sql.planner.plan.PlanNode)9 Symbol (com.facebook.presto.sql.planner.Symbol)8 LongLiteral (com.facebook.presto.sql.tree.LongLiteral)8 Cast (com.facebook.presto.sql.tree.Cast)6 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)6 ArithmeticBinaryExpression (com.facebook.presto.sql.tree.ArithmeticBinaryExpression)5 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)5 Identifier (com.facebook.presto.sql.tree.Identifier)5 QuerySpecification (com.facebook.presto.sql.tree.QuerySpecification)5 Map (java.util.Map)5 WindowNode (com.facebook.presto.sql.planner.plan.WindowNode)4 LambdaExpression (com.facebook.presto.sql.tree.LambdaExpression)4 LogicalBinaryExpression (com.facebook.presto.sql.tree.LogicalBinaryExpression)4 Query (com.facebook.presto.sql.tree.Query)4