use of com.facebook.presto.common.function.SqlFunctionProperties in project presto by prestodb.
the class LambdaBytecodeGenerator method generateMethodsForLambda.
private static Map<LambdaDefinitionExpression, CompiledLambda> generateMethodsForLambda(ClassDefinition containerClassDefinition, CallSiteBinder callSiteBinder, CachedInstanceBinder cachedInstanceBinder, List<RowExpression> expressions, Metadata metadata, SqlFunctionProperties sqlFunctionProperties, Map<SqlFunctionId, SqlInvokedFunction> sessionFunctions, String methodNamePrefix, Set<LambdaDefinitionExpression> existingCompiledLambdas) {
Set<LambdaDefinitionExpression> lambdaExpressions = expressions.stream().map(LambdaExpressionExtractor::extractLambdaExpressions).flatMap(List::stream).filter(lambda -> !existingCompiledLambdas.contains(lambda)).collect(toImmutableSet());
ImmutableMap.Builder<LambdaDefinitionExpression, CompiledLambda> compiledLambdaMap = ImmutableMap.builder();
int counter = existingCompiledLambdas.size();
for (LambdaDefinitionExpression lambdaExpression : lambdaExpressions) {
CompiledLambda compiledLambda = LambdaBytecodeGenerator.preGenerateLambdaExpression(lambdaExpression, methodNamePrefix + "lambda_" + counter, containerClassDefinition, compiledLambdaMap.build(), callSiteBinder, cachedInstanceBinder, metadata, sqlFunctionProperties, sessionFunctions);
compiledLambdaMap.put(lambdaExpression, compiledLambda);
counter++;
}
return compiledLambdaMap.build();
}
use of com.facebook.presto.common.function.SqlFunctionProperties in project presto by prestodb.
the class LambdaBytecodeGenerator method preGenerateLambdaExpression.
/**
* @return a MethodHandle field that represents the lambda expression
*/
private static CompiledLambda preGenerateLambdaExpression(LambdaDefinitionExpression lambdaExpression, String methodName, ClassDefinition classDefinition, Map<LambdaDefinitionExpression, CompiledLambda> compiledLambdaMap, CallSiteBinder callSiteBinder, CachedInstanceBinder cachedInstanceBinder, Metadata metadata, SqlFunctionProperties sqlFunctionProperties, Map<SqlFunctionId, SqlInvokedFunction> sessionFunctions) {
ImmutableList.Builder<Parameter> parameters = ImmutableList.builder();
ImmutableMap.Builder<String, ParameterAndType> parameterMapBuilder = ImmutableMap.builder();
parameters.add(arg("properties", SqlFunctionProperties.class));
for (int i = 0; i < lambdaExpression.getArguments().size(); i++) {
Class<?> type = Primitives.wrap(lambdaExpression.getArgumentTypes().get(i).getJavaType());
String argumentName = lambdaExpression.getArguments().get(i);
Parameter arg = arg("lambda_" + argumentName, type);
parameters.add(arg);
parameterMapBuilder.put(argumentName, new ParameterAndType(arg, type));
}
RowExpressionCompiler innerExpressionCompiler = new RowExpressionCompiler(classDefinition, callSiteBinder, cachedInstanceBinder, variableReferenceCompiler(parameterMapBuilder.build()), metadata, sqlFunctionProperties, sessionFunctions, compiledLambdaMap);
return defineLambdaMethod(innerExpressionCompiler, classDefinition, methodName, parameters.build(), lambdaExpression);
}
Aggregations