kafka-connect-transform-common
kafka-connect-transform-common copied to clipboard
Pattern replace to add a prefix
Thanks for this open source project.
I am facing an issue whereby some json like messages are having numeric filed names that break the final avrò schemas I would like to use the pattern replace transform to add a prefix/suffix to all fields that are numeric.
I don't know how many fields will satisfy this property so i cannot use a regular ReplaceField to rename those fields in advance
Can this be achieved with something like
pattern: "/d" Replace with: "prefix_$1_suffix"
?
here an example of the java matcher class: https://www.tutorialspoint.com/javaregex/javaregex_matcher_replaceall.htm
seems like regex groups could work: https://github.com/jcustenborder/kafka-connect-transform-common/blob/master/src/main/java/com/github/jcustenborder/kafka/connect/transform/common/PatternRename.java#L76
this way also this should work:
{
"transforms" : "patternRename",
"transforms.patternRename.type" : "com.github.jcustenborder.kafka.connect.transform.common.PatternRename$Value",
"transforms.patternRename.field.pattern" : "^[^\d]*(\d+)",
"transforms.patternRename.field.replacement" : "prefix$1"
}