Replace transform plugin

Description

Examines string value in a given field and replaces substring of the string value that matches the given string literal or regexes with the given replacement.

Options

name type required default value
replace_field string yes
pattern string yes -
replacement string yes -
is_regex boolean no false
replace_first boolean no false

replace_field [string]

The field you want to replace

pattern [string]

The old string that will be replaced

replacement [string]

The new string for replace

is_regex [boolean]

Use regex for string match

replace_first [boolean]

Whether replace the first match string. Only used when is_regex = true.

common options [string]

Transform plugin common parameters, please refer to Transform Plugin for details

Example

The data read from source is a table like this:

name age card
Joy Ding 20 123
May Ding 20 123
Kin Dom 20 123
Joy Dom 20 123

We want to replace the char ` to_at thenamefield. Then we can add aReplace` Transform like this:

  1. transform {
  2. Replace {
  3. source_table_name = "fake"
  4. result_table_name = "fake1"
  5. replace_field = "name"
  6. pattern = " "
  7. replacement = "_"
  8. is_regex = true
  9. }
  10. }

Then the data in result table fake1 will update to

name age card
Joy_Ding 20 123
May_Ding 20 123
Kin_Dom 20 123
Joy_Dom 20 123

Job Config Example

  1. env {
  2. job.mode = "BATCH"
  3. }
  4. source {
  5. FakeSource {
  6. result_table_name = "fake"
  7. row.num = 100
  8. schema = {
  9. fields {
  10. id = "int"
  11. name = "string"
  12. }
  13. }
  14. }
  15. }
  16. transform {
  17. Replace {
  18. source_table_name = "fake"
  19. result_table_name = "fake1"
  20. replace_field = "name"
  21. pattern = ".+"
  22. replacement = "b"
  23. is_regex = true
  24. }
  25. }
  26. sink {
  27. Console {
  28. source_table_name = "fake1"
  29. }
  30. }

Changelog

new version

  • Add Replace Transform Connector