use of io.confluent.ksql.function.udaf.UdafFactory in project ksql by confluentinc.
the class UdafLoader method loadUdafFromClass.
void loadUdafFromClass(final Class<?> theClass, final String path) {
final UdafDescription udafAnnotation = theClass.getAnnotation(UdafDescription.class);
final List<UdafFactoryInvoker> invokers = new ArrayList<>();
for (final Method method : theClass.getMethods()) {
if (method.getAnnotation(UdafFactory.class) == null) {
continue;
}
if (!Modifier.isStatic(method.getModifiers())) {
LOGGER.warn("Trying to create a UDAF from a non-static factory method. Udaf factory" + " methods must be static. class={}, method={}, name={}", method.getDeclaringClass(), method.getName(), udafAnnotation.name());
continue;
}
final UdafFactory annotation = method.getAnnotation(UdafFactory.class);
try {
LOGGER.info("Adding UDAF name={} from path={} class={}", udafAnnotation.name(), path, method.getDeclaringClass());
final UdafFactoryInvoker invoker = createUdafFactoryInvoker(method, FunctionName.of(udafAnnotation.name()), annotation.description(), annotation.paramSchema(), annotation.aggregateSchema(), annotation.returnSchema());
invokers.add(invoker);
} catch (final Exception e) {
LOGGER.warn("Failed to create UDAF name={}, method={}, class={}, path={}", udafAnnotation.name(), method.getName(), method.getDeclaringClass(), path, e);
}
}
functionRegistry.addAggregateFunctionFactory(new UdafAggregateFunctionFactory(new UdfMetadata(udafAnnotation.name(), udafAnnotation.description(), udafAnnotation.author(), udafAnnotation.version(), udafAnnotation.category(), path), invokers));
}
Aggregations