Annotation baseTypeAnnotation = baseTypeAnnotation(annotations[i], methodName); if (isImplementationDependencyAnnotation(baseTypeAnnotation)) { boolean isParameterBlock = isParameterBlock(annotations[i]); boolean isParameterNullable = isParameterNullable(annotations[i]); builder.add(inputChannelParameterType(isParameterNullable, isParameterBlock, methodName));
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(); }
private static Set<Class<?>> getStateClasses(Class<?> clazz) { ImmutableSet.Builder<Class<?>> builder = ImmutableSet.builder(); for (Method inputFunction : FunctionsParserHelper.findPublicStaticMethodsWithAnnotation(clazz, InputFunction.class)) { checkArgument(inputFunction.getParameterTypes().length > 0, "Input function has no parameters"); Class<?> stateClass = AggregationImplementation.Parser.findAggregationStateParamType(inputFunction); checkArgument(AccumulatorState.class.isAssignableFrom(stateClass), "stateClass is not a subclass of AccumulatorState"); builder.add(stateClass); } ImmutableSet<Class<?>> stateClasses = builder.build(); checkArgument(!stateClasses.isEmpty(), "No input functions found"); return stateClasses; } }
inputDependencies = parseImplementationDependencies(inputFunction); outputDependencies = parseImplementationDependencies(outputFunction); combineDependencies = parseImplementationDependencies(combineFunction); stateSerializerFactoryDependencies = stateSerializerFactoryFunction.map(this::parseImplementationDependencies).orElse(ImmutableList.of()); parameterMetadataTypes = parseParameterMetadataTypes(inputFunction); argumentNativeContainerTypes = parseSignatureArgumentsTypes(inputFunction); inputTypes = getInputTypesSignatures(inputFunction); returnType = parseTypeSignature(outputFunction.getAnnotation(OutputFunction.class).value(), literalParameters);
public static List<ParametricAggregation> parseFunctionDefinitions(Class<?> aggregationDefinition) { AggregationFunction aggregationAnnotation = aggregationDefinition.getAnnotation(AggregationFunction.class); requireNonNull(aggregationAnnotation, "aggregationAnnotation is null"); ImmutableList.Builder<ParametricAggregation> builder = ImmutableList.builder(); for (Class<?> stateClass : getStateClasses(aggregationDefinition)) { Method combineFunction = getCombineFunction(aggregationDefinition, stateClass); Optional<Method> aggregationStateSerializerFactory = getAggregationStateSerializerFactory(aggregationDefinition, stateClass); for (Method outputFunction : getOutputFunctions(aggregationDefinition, stateClass)) { for (Method inputFunction : getInputFunctions(aggregationDefinition, stateClass)) { for (AggregationHeader header : parseHeaders(aggregationDefinition, outputFunction)) { AggregationImplementation onlyImplementation = parseImplementation(aggregationDefinition, header, stateClass, inputFunction, outputFunction, combineFunction, aggregationStateSerializerFactory); ParametricImplementationsGroup<AggregationImplementation> implementations = ParametricImplementationsGroup.of(onlyImplementation); builder.add(new ParametricAggregation(implementations.getSignature(), header, implementations)); } } } } return builder.build(); }
public static ParametricAggregation parseFunctionDefinition(Class<?> aggregationDefinition) { ParametricImplementationsGroup.Builder<AggregationImplementation> implementationsBuilder = ParametricImplementationsGroup.builder(); AggregationHeader header = parseHeader(aggregationDefinition); for (Class<?> stateClass : getStateClasses(aggregationDefinition)) { Method combineFunction = getCombineFunction(aggregationDefinition, stateClass); Optional<Method> aggregationStateSerializerFactory = getAggregationStateSerializerFactory(aggregationDefinition, stateClass); Method outputFunction = getOnlyElement(getOutputFunctions(aggregationDefinition, stateClass)); for (Method inputFunction : getInputFunctions(aggregationDefinition, stateClass)) { AggregationImplementation implementation = parseImplementation(aggregationDefinition, header, stateClass, inputFunction, outputFunction, combineFunction, aggregationStateSerializerFactory); implementationsBuilder.addImplementation(implementation); } } ParametricImplementationsGroup<AggregationImplementation> implementations = implementationsBuilder.build(); return new ParametricAggregation(implementations.getSignature(), header, implementations); }
public static int findAggregationStateParamId(Method method) { return findAggregationStateParamId(method, 0); }
public static Class<?> findAggregationStateParamType(Method inputFunction) { return inputFunction.getParameterTypes()[findAggregationStateParamId(inputFunction)]; }
private static Annotation baseTypeAnnotation(Annotation[] annotations, String methodName) { List<Annotation> baseTypes = Arrays.asList(annotations).stream() .filter(annotation -> isAggregationMetaAnnotation(annotation) || annotation instanceof SqlType) .collect(toImmutableList()); checkArgument(baseTypes.size() == 1, "Parameter of %s must have exactly one of @SqlType, @BlockIndex", methodName); boolean nullable = isParameterNullable(annotations); boolean isBlock = isParameterBlock(annotations); Annotation annotation = baseTypes.get(0); checkArgument((!isBlock && !nullable) || (annotation instanceof SqlType), "%s contains a parameter with @BlockPosition and/or @NullablePosition that is not @SqlType", methodName); return annotation; }
public static AggregationImplementation parseImplementation( Class<?> aggregationDefinition, AggregationHeader header, Class<?> stateClass, Method inputFunction, Method outputFunction, Method combineFunction, Optional<Method> stateSerializerFactoryFunction) { return new Parser(aggregationDefinition, header, stateClass, inputFunction, outputFunction, combineFunction, stateSerializerFactoryFunction).get(); }
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); }
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; }