Search in sources :

Example 1 with UdafFactory

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));
}
Also used : UdafDescription(io.confluent.ksql.function.udaf.UdafDescription) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) UdfMetadata(io.confluent.ksql.function.udf.UdfMetadata) UdafFactory(io.confluent.ksql.function.udaf.UdafFactory)

Aggregations

UdafDescription (io.confluent.ksql.function.udaf.UdafDescription)1 UdafFactory (io.confluent.ksql.function.udaf.UdafFactory)1 UdfMetadata (io.confluent.ksql.function.udf.UdfMetadata)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1