use of org.apache.beam.model.pipeline.v1.ExternalTransforms.BuilderMethod in project beam by apache.
the class JavaClassLookupTransformProvider method getMethod.
private Method getMethod(PTransform<PInput, POutput> transform, BuilderMethod builderMethod, AllowedClass allowListClass) {
Row builderMethodRow = decodeRow(builderMethod.getSchema(), builderMethod.getPayload());
List<Method> matchingMethods = Arrays.stream(transform.getClass().getMethods()).filter(m -> isBuilderMethodForName(m, builderMethod.getName(), allowListClass)).filter(m -> parametersCompatible(m.getParameters(), builderMethodRow)).filter(m -> PTransform.class.isAssignableFrom(m.getReturnType())).collect(Collectors.toList());
if (matchingMethods.size() == 0) {
throw new RuntimeException("Could not find a matching method in transform " + transform + " for BuilderMethod" + builderMethod + ". When using field names, make sure they are available in the compiled" + " Java class.");
} else if (matchingMethods.size() > 1) {
throw new RuntimeException("Expected to find exactly one matching method in transform " + transform + " for BuilderMethod" + builderMethod + " but found " + matchingMethods.size());
}
return matchingMethods.get(0);
}
use of org.apache.beam.model.pipeline.v1.ExternalTransforms.BuilderMethod in project beam by apache.
the class JavaClassLookupTransformProvider method applyBuilderMethods.
private PTransform<PInput, POutput> applyBuilderMethods(PTransform<PInput, POutput> transform, JavaClassLookupPayload payload, AllowedClass allowListClass) {
for (BuilderMethod builderMethod : payload.getBuilderMethodsList()) {
Method method = getMethod(transform, builderMethod, allowListClass);
try {
Row builderMethodRow = decodeRow(builderMethod.getSchema(), builderMethod.getPayload());
transform = (PTransform<PInput, POutput>) method.invoke(transform, getParameterValues(method.getParameters(), builderMethodRow, method.getGenericParameterTypes()));
} catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalArgumentException("Could not invoke the builder method " + builderMethod + " on transform " + transform + " with parameter schema " + builderMethod.getSchema(), e);
}
}
return transform;
}
Aggregations