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