Search in sources :

Example 1 with LambdaExpression

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

the class TestSqlParser method testLambda.

@Test
public void testLambda() throws Exception {
    assertExpression("x -> sin(x)", new LambdaExpression(ImmutableList.of(new LambdaArgumentDeclaration("x")), new FunctionCall(QualifiedName.of("sin"), ImmutableList.of(new Identifier("x")))));
    assertExpression("(x, y) -> mod(x, y)", new LambdaExpression(ImmutableList.of(new LambdaArgumentDeclaration("x"), new LambdaArgumentDeclaration("y")), new FunctionCall(QualifiedName.of("mod"), ImmutableList.of(new Identifier("x"), new Identifier("y")))));
}
Also used : LambdaArgumentDeclaration(com.facebook.presto.sql.tree.LambdaArgumentDeclaration) Identifier(com.facebook.presto.sql.tree.Identifier) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) LambdaExpression(com.facebook.presto.sql.tree.LambdaExpression) Test(org.testng.annotations.Test)

Example 2 with LambdaExpression

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

the class AstBuilder method visitLambda.

@Override
public Node visitLambda(SqlBaseParser.LambdaContext context) {
    List<LambdaArgumentDeclaration> arguments = context.identifier().stream().map(SqlBaseParser.IdentifierContext::getText).map(LambdaArgumentDeclaration::new).collect(toList());
    Expression body = (Expression) visit(context.expression());
    return new LambdaExpression(arguments, body);
}
Also used : LambdaArgumentDeclaration(com.facebook.presto.sql.tree.LambdaArgumentDeclaration) SubqueryExpression(com.facebook.presto.sql.tree.SubqueryExpression) SubscriptExpression(com.facebook.presto.sql.tree.SubscriptExpression) LogicalBinaryExpression(com.facebook.presto.sql.tree.LogicalBinaryExpression) SearchedCaseExpression(com.facebook.presto.sql.tree.SearchedCaseExpression) CoalesceExpression(com.facebook.presto.sql.tree.CoalesceExpression) SimpleCaseExpression(com.facebook.presto.sql.tree.SimpleCaseExpression) NotExpression(com.facebook.presto.sql.tree.NotExpression) LambdaExpression(com.facebook.presto.sql.tree.LambdaExpression) IfExpression(com.facebook.presto.sql.tree.IfExpression) QuantifiedComparisonExpression(com.facebook.presto.sql.tree.QuantifiedComparisonExpression) InListExpression(com.facebook.presto.sql.tree.InListExpression) TryExpression(com.facebook.presto.sql.tree.TryExpression) ArithmeticUnaryExpression(com.facebook.presto.sql.tree.ArithmeticUnaryExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) NullIfExpression(com.facebook.presto.sql.tree.NullIfExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) ArithmeticBinaryExpression(com.facebook.presto.sql.tree.ArithmeticBinaryExpression) LambdaExpression(com.facebook.presto.sql.tree.LambdaExpression)

Aggregations

LambdaArgumentDeclaration (com.facebook.presto.sql.tree.LambdaArgumentDeclaration)2 LambdaExpression (com.facebook.presto.sql.tree.LambdaExpression)2 ArithmeticBinaryExpression (com.facebook.presto.sql.tree.ArithmeticBinaryExpression)1 ArithmeticUnaryExpression (com.facebook.presto.sql.tree.ArithmeticUnaryExpression)1 CoalesceExpression (com.facebook.presto.sql.tree.CoalesceExpression)1 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)1 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)1 Expression (com.facebook.presto.sql.tree.Expression)1 FunctionCall (com.facebook.presto.sql.tree.FunctionCall)1 Identifier (com.facebook.presto.sql.tree.Identifier)1 IfExpression (com.facebook.presto.sql.tree.IfExpression)1 InListExpression (com.facebook.presto.sql.tree.InListExpression)1 LogicalBinaryExpression (com.facebook.presto.sql.tree.LogicalBinaryExpression)1 NotExpression (com.facebook.presto.sql.tree.NotExpression)1 NullIfExpression (com.facebook.presto.sql.tree.NullIfExpression)1 QuantifiedComparisonExpression (com.facebook.presto.sql.tree.QuantifiedComparisonExpression)1 SearchedCaseExpression (com.facebook.presto.sql.tree.SearchedCaseExpression)1 SimpleCaseExpression (com.facebook.presto.sql.tree.SimpleCaseExpression)1 SubqueryExpression (com.facebook.presto.sql.tree.SubqueryExpression)1 SubscriptExpression (com.facebook.presto.sql.tree.SubscriptExpression)1