@Override protected Boolean visitLambdaExpression(LambdaExpression node, Void context) { return process(node.getBody(), context); }
@Override protected String visitLambdaExpression(LambdaExpression node, Void context) { StringBuilder builder = new StringBuilder(); builder.append('('); Joiner.on(", ").appendTo(builder, node.getArguments()); builder.append(") -> "); builder.append(process(node.getBody(), context)); return builder.toString(); }
@Override protected Void visitLambdaExpression(LambdaExpression node, Set<String> lambdaArgumentNames) { return process(node.getBody(), ImmutableSet.<String>builder() .addAll(lambdaArgumentNames) .addAll(node.getArguments().stream() .map(LambdaArgumentDeclaration::getName) .map(Identifier::getValue) .collect(toImmutableSet())) .build()); } }
@Override protected RowExpression visitLambdaExpression(LambdaExpression node, Void context) { RowExpression body = process(node.getBody(), context); Type type = getType(node); List<Type> typeParameters = type.getTypeParameters(); List<Type> argumentTypes = typeParameters.subList(0, typeParameters.size() - 1); List<String> argumentNames = node.getArguments().stream() .map(LambdaArgumentDeclaration::getName) .map(Identifier::getValue) .collect(toImmutableList()); return new LambdaDefinitionExpression(argumentTypes, argumentNames, body); }
@Override public Expression rewriteLambdaExpression(LambdaExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { return new LambdaExpression(node.getArguments(), treeRewriter.rewrite(node.getBody(), context)); } }, expression);
@Override public Expression rewriteLambdaExpression(LambdaExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { checkState(analysis.getCoercion(node) == null, "cannot coerce a lambda expression"); ImmutableList.Builder<LambdaArgumentDeclaration> newArguments = ImmutableList.builder(); for (LambdaArgumentDeclaration argument : node.getArguments()) { Symbol symbol = lambdaDeclarationToSymbolMap.get(NodeRef.of(argument)); newArguments.add(new LambdaArgumentDeclaration(new Identifier(symbol.getName()))); } Expression rewrittenBody = treeRewriter.rewrite(node.getBody(), null); return new LambdaExpression(newArguments.build(), rewrittenBody); }
@Override protected Object visitLambdaExpression(LambdaExpression node, Object context) { if (optimize) { // TODO: enable optimization related to lambda expression // A mechanism to convert function type back into lambda expression need to exist to enable optimization return node; } Expression body = node.getBody(); List<String> argumentNames = node.getArguments().stream() .map(LambdaArgumentDeclaration::getName) .map(Identifier::getValue) .collect(toImmutableList()); FunctionType functionType = (FunctionType) expressionTypes.get(NodeRef.<Expression>of(node)); checkArgument(argumentNames.size() == functionType.getArgumentTypes().size()); return generateVarArgsToMapAdapter( Primitives.wrap(functionType.getReturnType().getJavaType()), functionType.getArgumentTypes().stream() .map(Type::getJavaType) .map(Primitives::wrap) .collect(toImmutableList()), argumentNames, map -> process(body, new LambdaSymbolResolver(map))); }
Expression rewrittenBody = treeRewriter.rewrite(node.getBody(), context.withReferencedSymbols(referencedSymbols));
sqlParser, TypeProvider.copyOf(lambdaArgumentSymbolTypes), lambdaExpression.getBody(), emptyList(), NOOP))
@Override protected Type visitLambdaExpression(LambdaExpression node, StackableAstVisitorContext<Context> context) verifyNoAggregateWindowOrGroupingFunctions(functionRegistry, node.getBody(), "Lambda expression"); if (!context.getContext().isExpectingLambda()) { throw new SemanticException(STANDALONE_LAMBDA, node, "Lambda expression should always be used inside a function"); Type returnType = process(node.getBody(), new StackableAstVisitorContext<>(Context.inLambda(lambdaScope, fieldToLambdaArgumentDeclaration.build()))); FunctionType functionType = new FunctionType(types, returnType); return setExpressionType(node, functionType);
@Override protected String visitLambdaExpression(LambdaExpression node, Void context) { StringBuilder builder = new StringBuilder(); builder.append('('); Joiner.on(", ").appendTo(builder, node.getArguments()); builder.append(") -> "); builder.append(process(node.getBody(), context)); return builder.toString(); }
@Override protected String visitLambdaExpression(LambdaExpression node, Boolean unmangleNames) { StringBuilder builder = new StringBuilder(); builder.append('('); Joiner.on(", ").appendTo(builder, node.getArguments()); builder.append(") -> "); builder.append(process(node.getBody(), unmangleNames)); return builder.toString(); }
@Override protected String visitLambdaExpression(LambdaExpression node, Void context) { StringBuilder builder = new StringBuilder(); builder.append('('); Joiner.on(", ").appendTo(builder, node.getArguments()); builder.append(") -> "); builder.append(process(node.getBody(), context)); return builder.toString(); }
@Override protected String visitLambdaExpression(LambdaExpression node, Boolean unmangleNames) { StringBuilder builder = new StringBuilder(); builder.append('('); Joiner.on(", ").appendTo(builder, node.getArguments()); builder.append(") -> "); builder.append(process(node.getBody(), unmangleNames)); return builder.toString(); }