@Override public void generateMethods(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, RowExpression filter, List<RowExpression> projections) { CachedInstanceBinder cachedInstanceBinder = new CachedInstanceBinder(classDefinition, callSiteBinder); generateProcessMethod(classDefinition, projections.size()); Map<LambdaDefinitionExpression, CompiledLambda> filterCompiledLambdaMap = generateMethodsForLambda(classDefinition, callSiteBinder, cachedInstanceBinder, filter, "filter"); generateFilterMethod(classDefinition, callSiteBinder, cachedInstanceBinder, filterCompiledLambdaMap, filter); for (int i = 0; i < projections.size(); i++) { String methodName = "project_" + i; Map<LambdaDefinitionExpression, CompiledLambda> projectCompiledLambdaMap = generateMethodsForLambda(classDefinition, callSiteBinder, cachedInstanceBinder, projections.get(i), methodName); generateProjectMethod(classDefinition, callSiteBinder, cachedInstanceBinder, projectCompiledLambdaMap, methodName, projections.get(i)); } MethodDefinition constructorDefinition = classDefinition.declareConstructor(a(PUBLIC)); BytecodeBlock constructorBody = constructorDefinition.getBody(); Variable thisVariable = constructorDefinition.getThis(); constructorBody.comment("super();") .append(thisVariable) .invokeConstructor(Object.class); cachedInstanceBinder.generateInitializations(thisVariable, constructorBody); constructorBody.ret(); }
public static BytecodeExpression invokeFunction(Scope scope, CachedInstanceBinder cachedInstanceBinder, String name, ScalarFunctionImplementation function, List<BytecodeExpression> parameters) { requireNonNull(scope, "scope is null"); requireNonNull(function, "function is null"); Optional<BytecodeNode> instance = Optional.empty(); if (function.getInstanceFactory().isPresent()) { FieldDefinition field = cachedInstanceBinder.getCachedInstance(function.getInstanceFactory().get()); instance = Optional.of(scope.getThis().getField(field)); } return new InvokeFunctionBytecodeExpression(scope, cachedInstanceBinder.getCallSiteBinder(), name, function, instance, parameters); }
private void generateMethods(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, RowExpression filter, int leftBlocksSize) { CachedInstanceBinder cachedInstanceBinder = new CachedInstanceBinder(classDefinition, callSiteBinder); FieldDefinition sessionField = classDefinition.declareField(a(PRIVATE, FINAL), "session", ConnectorSession.class); Map<LambdaDefinitionExpression, CompiledLambda> compiledLambdaMap = generateMethodsForLambda(classDefinition, callSiteBinder, cachedInstanceBinder, leftBlocksSize, filter); generateFilterMethod(classDefinition, callSiteBinder, cachedInstanceBinder, compiledLambdaMap, filter, leftBlocksSize, sessionField); generateConstructor(classDefinition, sessionField, cachedInstanceBinder); }
private static void generateConstructor( ClassDefinition classDefinition, CachedInstanceBinder cachedInstanceBinder, Map<LambdaDefinitionExpression, CompiledLambda> compiledLambdaMap, Consumer<MethodDefinition> additionalStatements) { MethodDefinition constructorDefinition = classDefinition.declareConstructor(a(PUBLIC)); BytecodeBlock body = constructorDefinition.getBody(); Variable thisVariable = constructorDefinition.getThis(); body.comment("super();") .append(thisVariable) .invokeConstructor(Object.class); additionalStatements.accept(constructorDefinition); cachedInstanceBinder.generateInitializations(thisVariable, body); body.ret(); }
public static ArrayMapBytecodeExpression map(Scope scope, CachedInstanceBinder cachedInstanceBinder, Type fromElementType, Type toElementType, Variable array, String elementFunctionName, ScalarFunctionImplementation elementFunction) { return map( scope, cachedInstanceBinder.getCallSiteBinder(), fromElementType, toElementType, array, element -> invokeFunction(scope, cachedInstanceBinder, elementFunctionName, elementFunction, element)); }
/** * Generates a function call with null handling, automatic binding of session parameter, etc. */ public BytecodeNode generateCall( String name, ScalarFunctionImplementation function, List<BytecodeNode> arguments, Optional<OutputBlockVariableAndType> outputBlockVariableAndType) { Optional<BytecodeNode> instance = Optional.empty(); if (function.getInstanceFactory().isPresent()) { FieldDefinition field = cachedInstanceBinder.getCachedInstance(function.getInstanceFactory().get()); instance = Optional.of(scope.getThis().getField(field)); } return generateInvocation(scope, name, function, instance, arguments, callSiteBinder, outputBlockVariableAndType); }
type(PageFilter.class)); CachedInstanceBinder cachedInstanceBinder = new CachedInstanceBinder(classDefinition, callSiteBinder);
private static void generateConstructor( ClassDefinition classDefinition, FieldDefinition sessionField, CachedInstanceBinder cachedInstanceBinder) { Parameter sessionParameter = arg("session", ConnectorSession.class); MethodDefinition constructorDefinition = classDefinition.declareConstructor(a(PUBLIC), sessionParameter); BytecodeBlock body = constructorDefinition.getBody(); Variable thisVariable = constructorDefinition.getThis(); body.comment("super();") .append(thisVariable) .invokeConstructor(Object.class); body.append(thisVariable.setField(sessionField, sessionParameter)); cachedInstanceBinder.generateInitializations(thisVariable, body); body.ret(); }
public static ArrayMapBytecodeExpression map(Scope scope, CachedInstanceBinder cachedInstanceBinder, Type fromElementType, Type toElementType, Variable array, String elementFunctionName, ScalarFunctionImplementation elementFunction) { return map( scope, cachedInstanceBinder.getCallSiteBinder(), fromElementType, toElementType, array, element -> invokeFunction(scope, cachedInstanceBinder, elementFunctionName, elementFunction, element)); }
/** * Generates a function call with null handling, automatic binding of session parameter, etc. */ public BytecodeNode generateCall(String name, ScalarFunctionImplementation function, List<BytecodeNode> arguments) { Binding binding = callSiteBinder.bind(function.getMethodHandle()); Optional<BytecodeNode> instance = Optional.empty(); if (function.getInstanceFactory().isPresent()) { FieldDefinition field = cachedInstanceBinder.getCachedInstance(function.getInstanceFactory().get()); instance = Optional.of(scope.getThis().getField(field)); } return generateInvocation(scope, name, function, instance, arguments, binding); }
CachedInstanceBinder cachedInstanceBinder = new CachedInstanceBinder(definition, binder); ArrayMapBytecodeExpression newArray = ArrayGeneratorUtils.map(scope, cachedInstanceBinder, fromElementType, toElementType, value, elementCastSignature.getName(), elementCast); .append(thisVariable) .invokeConstructor(Object.class); cachedInstanceBinder.generateInitializations(thisVariable, constructorBody); constructorBody.ret();
private Filter compileRowExpression(RowExpression filter) { ParameterizedType className = CompilerUtils.makeClassName(Filter.class.getSimpleName()); ParameterizedType[] interfaces = {ParameterizedType.type(Filter.class)}; ParameterizedType type = ParameterizedType.type(Object.class); EnumSet<Access> accessList = a(new Access[]{PUBLIC, FINAL}); ClassDefinition classDefinition = new ClassDefinition(accessList, className, type, interfaces); classDefinition.declareDefaultConstructor(a(PUBLIC)); CallSiteBinder callSiteBinder = new CallSiteBinder(); CursorProcessorCompiler cursorProcessorCompiler = new CursorProcessorCompiler(metadata); Method method; try { method = cursorProcessorCompiler.getClass().getDeclaredMethod("generateFilterMethod", ClassDefinition.class, CallSiteBinder.class, CachedInstanceBinder.class, RowExpression.class); method.setAccessible(true); } catch (NoSuchMethodException e) { throw Throwables.propagate(e); } try { method.invoke(cursorProcessorCompiler, classDefinition, callSiteBinder, new CachedInstanceBinder(classDefinition, callSiteBinder), filter); } catch (IllegalAccessException | InvocationTargetException e) { throw Throwables.propagate(e); } Class<? extends Filter> aClass = defineClass(classDefinition, Filter.class, callSiteBinder.getBindings(), getClass().getClassLoader()); try { return aClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException("Couldn't compile expression", e); } }
public static BytecodeExpression invokeFunction(Scope scope, CachedInstanceBinder cachedInstanceBinder, String name, ScalarFunctionImplementation function, List<BytecodeExpression> parameters) { requireNonNull(scope, "scope is null"); requireNonNull(function, "function is null"); Binding binding = cachedInstanceBinder.getCallSiteBinder().bind(function.getMethodHandle()); Optional<BytecodeNode> instance = Optional.empty(); if (function.getInstanceFactory().isPresent()) { FieldDefinition field = cachedInstanceBinder.getCachedInstance(function.getInstanceFactory().get()); instance = Optional.of(scope.getThis().getField(field)); } return new InvokeFunctionBytecodeExpression(scope, binding, name, function, instance, parameters); }
private static void generateConstructor(ClassDefinition classDefinition, CachedInstanceBinder cachedInstanceBinder, int projectionCount) { MethodDefinition constructorDefinition = classDefinition.declareConstructor(a(PUBLIC)); FieldDefinition inputDictionaries = classDefinition.declareField(a(PRIVATE, FINAL), "inputDictionaries", Block[].class); FieldDefinition outputDictionaries = classDefinition.declareField(a(PRIVATE, FINAL), "outputDictionaries", Block[].class); FieldDefinition inputFilterDictionary = classDefinition.declareField(a(PRIVATE), "inputFilterDictionary", Block.class); FieldDefinition filterResult = classDefinition.declareField(a(PRIVATE), "filterResult", boolean[].class); BytecodeBlock body = constructorDefinition.getBody(); Variable thisVariable = constructorDefinition.getThis(); body.comment("super();") .append(thisVariable) .invokeConstructor(Object.class); body.append(thisVariable.setField(inputDictionaries, newArray(type(Block[].class), projectionCount))); body.append(thisVariable.setField(outputDictionaries, newArray(type(Block[].class), projectionCount))); body.append(thisVariable.setField(inputFilterDictionary, constantNull(Block.class))); body.append(thisVariable.setField(filterResult, constantNull(boolean[].class))); cachedInstanceBinder.generateInitializations(thisVariable, body); body.ret(); }
CachedInstanceBinder cachedInstanceBinder = new CachedInstanceBinder(definition, binder); .append(thisVariable) .invokeConstructor(Object.class); cachedInstanceBinder.generateInitializations(thisVariable, constructorBody); constructorBody.ret();
@Override public void generateMethods(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, RowExpression filter, List<RowExpression> projections) { CachedInstanceBinder cachedInstanceBinder = new CachedInstanceBinder(classDefinition, callSiteBinder); ImmutableList.Builder<MethodDefinition> projectMethods = ImmutableList.builder(); ImmutableList.Builder<MethodDefinition> projectColumnarMethods = ImmutableList.builder(); ImmutableList.Builder<MethodDefinition> projectDictionaryMethods = ImmutableList.builder(); for (int i = 0; i < projections.size(); i++) { MethodDefinition project = generateProjectMethod(classDefinition, callSiteBinder, cachedInstanceBinder, "project_" + i, projections.get(i)); MethodDefinition projectColumnar = generateProjectColumnarMethod(classDefinition, callSiteBinder, "projectColumnar_" + i, projections.get(i), project); MethodDefinition projectRLE = generateProjectRLEMethod(classDefinition, "projectRLE_" + i, projections.get(i), project, projectColumnar); MethodDefinition projectDictionary = generateProjectDictionaryMethod(classDefinition, "projectDictionary_" + i, projections.get(i), project, projectColumnar, projectRLE); projectMethods.add(project); projectColumnarMethods.add(projectColumnar); projectDictionaryMethods.add(projectDictionary); } List<MethodDefinition> projectMethodDefinitions = projectMethods.build(); List<MethodDefinition> projectColumnarMethodDefinitions = projectColumnarMethods.build(); List<MethodDefinition> projectDictionaryMethodDefinitions = projectDictionaryMethods.build(); generateProcessMethod(classDefinition, filter, projections, projectMethodDefinitions); generateGetNonLazyPageMethod(classDefinition, filter, projections); generateProcessColumnarMethod(classDefinition, projections, projectColumnarMethodDefinitions); generateProcessColumnarDictionaryMethod(classDefinition, projections, projectDictionaryMethodDefinitions); generateFilterPageMethod(classDefinition, filter); generateFilterMethod(classDefinition, callSiteBinder, cachedInstanceBinder, filter); generateConstructor(classDefinition, cachedInstanceBinder, projections.size()); }
CachedInstanceBinder cachedInstanceBinder = new CachedInstanceBinder(lambdaProviderClassDefinition, callSiteBinder); .append(constructorThisVariable.setField(sessionField, sessionParameter)); cachedInstanceBinder.generateInitializations(constructorThisVariable, constructorBody); constructorBody.ret();
body.append(wasNull.set(constantFalse())); CachedInstanceBinder cachedInstanceBinder = new CachedInstanceBinder(definition, binder); .append(thisVariable) .invokeConstructor(Object.class); cachedInstanceBinder.generateInitializations(thisVariable, constructorBody); constructorBody.ret();
FieldDefinition resultField = classDefinition.declareField(a(PRIVATE), "result", Block.class); CachedInstanceBinder cachedInstanceBinder = new CachedInstanceBinder(classDefinition, callSiteBinder); .append(thisVariable.setField(resultField, constantNull(Block.class))); cachedInstanceBinder.generateInitializations(thisVariable, body); body.ret();
@Override public void generateMethods(ClassDefinition classDefinition, CallSiteBinder callSiteBinder, RowExpression filter, List<RowExpression> projections) { CachedInstanceBinder cachedInstanceBinder = new CachedInstanceBinder(classDefinition, callSiteBinder); generateProcessMethod(classDefinition, projections.size()); generateFilterMethod(classDefinition, callSiteBinder, cachedInstanceBinder, filter); for (int i = 0; i < projections.size(); i++) { generateProjectMethod(classDefinition, callSiteBinder, cachedInstanceBinder, "project_" + i, projections.get(i)); } MethodDefinition constructorDefinition = classDefinition.declareConstructor(a(PUBLIC)); BytecodeBlock constructorBody = constructorDefinition.getBody(); Variable thisVariable = constructorDefinition.getThis(); constructorBody.comment("super();") .append(thisVariable) .invokeConstructor(Object.class); cachedInstanceBinder.generateInitializations(thisVariable, constructorBody); constructorBody.ret(); }