Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern replace to add a prefix #95

Open
dberardo opened this issue Dec 19, 2022 · 1 comment
Open

Pattern replace to add a prefix #95

dberardo opened this issue Dec 19, 2022 · 1 comment

Comments

@dberardo
Copy link

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-com
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants