kafka-connect-transform-common icon indicating copy to clipboard operation
kafka-connect-transform-common copied to clipboard

Pattern replace to add a prefix

Open dberardo opened this issue 2 years ago • 1 comments

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"

?

dberardo avatar Dec 19 '22 21:12 dberardo

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"
}

dberardo-com avatar Jan 23 '23 15:01 dberardo-com