Created
June 29, 2018 08:12
-
-
Save miguno/80fb0ceed7f0456da52f5e34746c65d3 to your computer and use it in GitHub Desktop.
UDAF example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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