Search in sources :

Example 1 with LambdaArgumentDeclaration

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

the class LogicalPlanner method buildLambdaDeclarationToSymbolMap.

private static IdentityLinkedHashMap<LambdaArgumentDeclaration, Symbol> buildLambdaDeclarationToSymbolMap(Analysis analysis, SymbolAllocator symbolAllocator) {
    IdentityLinkedHashMap<LambdaArgumentDeclaration, Symbol> resultMap = new IdentityLinkedHashMap<>();
    for (Map.Entry<Expression, Type> entry : analysis.getTypes().entrySet()) {
        if (!(entry.getKey() instanceof LambdaArgumentDeclaration)) {
            continue;
        }
        LambdaArgumentDeclaration lambdaArgumentDeclaration = (LambdaArgumentDeclaration) entry.getKey();
        if (resultMap.containsKey(lambdaArgumentDeclaration)) {
            continue;
        }
        resultMap.put(lambdaArgumentDeclaration, symbolAllocator.newSymbol(lambdaArgumentDeclaration, entry.getValue()));
    }
    return resultMap;
}
Also used : IdentityLinkedHashMap(com.facebook.presto.util.maps.IdentityLinkedHashMap) Type(com.facebook.presto.spi.type.Type) RelationType(com.facebook.presto.sql.analyzer.RelationType) LambdaArgumentDeclaration(com.facebook.presto.sql.tree.LambdaArgumentDeclaration) Expression(com.facebook.presto.sql.tree.Expression) Map(java.util.Map) IdentityLinkedHashMap(com.facebook.presto.util.maps.IdentityLinkedHashMap)

Example 2 with LambdaArgumentDeclaration

use of com.facebook.presto.sql.tree.LambdaArgumentDeclaration 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 3 with LambdaArgumentDeclaration

use of com.facebook.presto.sql.tree.LambdaArgumentDeclaration 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)3 Expression (com.facebook.presto.sql.tree.Expression)2 LambdaExpression (com.facebook.presto.sql.tree.LambdaExpression)2 Type (com.facebook.presto.spi.type.Type)1 RelationType (com.facebook.presto.sql.analyzer.RelationType)1 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 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