Skip to content

Instantly share code, notes, and snippets.

@miguno
Created June 29, 2018 08:12
Show Gist options
  • Save miguno/80fb0ceed7f0456da52f5e34746c65d3 to your computer and use it in GitHub Desktop.
Save miguno/80fb0ceed7f0456da52f5e34746c65d3 to your computer and use it in GitHub Desktop.
UDAF example
package com.myorg.ksql.udaf;
import io.confluent.ksql.function.udaf.UdafFactory;
import io.confluent.ksql.function.udf.UdfDescription;
@UdfDescription(name = "totalStringLength", author = "Confluent", version = "1.0")
public class TotalStringLength {
@UdafFactory(description = "sums the length of strings")
public static Udaf<String, Long> createSumLengthString() {
return new Udaf<String, Long>() {
@Override
public Long initialize() {
return 0L;
}
@Override
public Long aggregate(final String s, final Long aggregate) {
return aggregate + s.length();
}
@Override
public Long merge(final Long aggOne, final Long aggTwo) {
return aggOne + aggTwo;
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment