private static List<Method> getInputFunctions(Class<?> clazz, Class<?> stateClass) { // Only include methods that match this state class List<Method> inputFunctions = FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(clazz, InputFunction.class).stream() .filter(method -> (method.getParameterTypes()[AggregationImplementation.Parser.findAggregationStateParamId(method)] == stateClass)) .collect(toImmutableList()); checkArgument(!inputFunctions.isEmpty(), "Aggregation has no input functions"); return inputFunctions; }
private static List<Method> getOutputFunctions(Class<?> clazz, Class<?> stateClass) { // Only include methods that match this state class List<Method> outputFunctions = FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(clazz, OutputFunction.class).stream() .filter(method -> method.getParameterTypes()[AggregationImplementation.Parser.findAggregationStateParamId(method)] == stateClass) .collect(toImmutableList()); checkArgument(!outputFunctions.isEmpty(), "Aggregation has no output functions"); return outputFunctions; }
public static Method getCombineFunction(Class<?> clazz, Class<?> stateClass) { // Only include methods that match this state class List<Method> combineFunctions = FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(clazz, CombineFunction.class).stream() .filter(method -> method.getParameterTypes()[AggregationImplementation.Parser.findAggregationStateParamId(method, 0)] == stateClass) .filter(method -> method.getParameterTypes()[AggregationImplementation.Parser.findAggregationStateParamId(method, 1)] == stateClass) .collect(toImmutableList()); checkArgument(combineFunctions.size() == 1, String.format("There must be exactly one @CombineFunction in class %s for the @AggregationState %s ", clazz.toGenericString(), stateClass.toGenericString())); return getOnlyElement(combineFunctions); }
public static List<AggregateNativeContainerType> parseSignatureArgumentsTypes(Method inputFunction) { ImmutableList.Builder<AggregateNativeContainerType> builder = ImmutableList.builder(); int stateId = findAggregationStateParamId(inputFunction); for (int i = 0; i < inputFunction.getParameterCount(); i++) { Class<?> parameterType = inputFunction.getParameterTypes()[i]; Annotation[] annotations = inputFunction.getParameterAnnotations()[i]; // Skip injected parameters if (parameterType == ConnectorSession.class) { continue; } if (containsAnnotation(annotations, Parser::isAggregationMetaAnnotation)) { continue; } builder.add(new AggregateNativeContainerType(inputFunction.getParameterTypes()[i], isParameterBlock(annotations))); } return builder.build(); }
public static int findAggregationStateParamId(Method method) { return findAggregationStateParamId(method, 0); }
public static Class<?> findAggregationStateParamType(Method inputFunction) { return inputFunction.getParameterTypes()[findAggregationStateParamId(inputFunction)]; }