use of io.prestosql.operator.aggregation.LambdaProvider in project hetu-core by openlookeng.
the class LambdaBytecodeGenerator method compileLambdaProvider.
public static Class<? extends LambdaProvider> compileLambdaProvider(LambdaDefinitionExpression lambdaExpression, Metadata metadata, Class<?> lambdaInterface) {
ClassDefinition lambdaProviderClassDefinition = new ClassDefinition(a(PUBLIC, Access.FINAL), makeClassName("LambdaProvider"), type(Object.class), type(LambdaProvider.class));
FieldDefinition sessionField = lambdaProviderClassDefinition.declareField(a(PRIVATE), "session", ConnectorSession.class);
CallSiteBinder callSiteBinder = new CallSiteBinder();
CachedInstanceBinder cachedInstanceBinder = new CachedInstanceBinder(lambdaProviderClassDefinition, callSiteBinder);
Map<LambdaDefinitionExpression, CompiledLambda> compiledLambdaMap = generateMethodsForLambda(lambdaProviderClassDefinition, callSiteBinder, cachedInstanceBinder, lambdaExpression, metadata);
MethodDefinition method = lambdaProviderClassDefinition.declareMethod(a(PUBLIC), "getLambda", type(Object.class), ImmutableList.of());
Scope scope = method.getScope();
BytecodeBlock body = method.getBody();
scope.declareVariable("wasNull", body, constantFalse());
scope.declareVariable("session", body, method.getThis().getField(sessionField));
RowExpressionCompiler rowExpressionCompiler = new RowExpressionCompiler(callSiteBinder, cachedInstanceBinder, variableReferenceCompiler(ImmutableMap.of()), metadata, compiledLambdaMap);
BytecodeGeneratorContext generatorContext = new BytecodeGeneratorContext(rowExpressionCompiler, scope, callSiteBinder, cachedInstanceBinder, metadata.getFunctionAndTypeManager());
body.append(generateLambda(generatorContext, ImmutableList.of(), compiledLambdaMap.get(lambdaExpression), lambdaInterface)).retObject();
// constructor
Parameter sessionParameter = arg("session", ConnectorSession.class);
MethodDefinition constructorDefinition = lambdaProviderClassDefinition.declareConstructor(a(PUBLIC), sessionParameter);
BytecodeBlock constructorBody = constructorDefinition.getBody();
Variable constructorThisVariable = constructorDefinition.getThis();
constructorBody.comment("super();").append(constructorThisVariable).invokeConstructor(Object.class).append(constructorThisVariable.setField(sessionField, sessionParameter));
cachedInstanceBinder.generateInitializations(constructorThisVariable, constructorBody);
constructorBody.ret();
return defineClass(lambdaProviderClassDefinition, LambdaProvider.class, callSiteBinder.getBindings(), AccumulatorCompiler.class.getClassLoader());
}
Aggregations