Kafka Connect ReplaceField (Confluent) SMT Usage Reference for Confluent Platform
The ReplaceField SMT (io.confluent.connect.transforms.ReplaceField) filters or renames fields, including nested fields, within a record’s Struct or Map.
Description
Filter or rename fields within a Struct or Map. Supports nested records.
Use the concrete transformation type designed for the record key (io.confluent.connect.transforms.ReplaceField$Key) or value (io.confluent.connect.transforms.ReplaceField$Value).
For the Apache Kafka® version, see ReplaceField (Apache Kafka).
Properties
Name | Description | Type | Default | Valid values | Importance |
|---|---|---|---|---|---|
| Fields to exclude from the resulting Struct or Map. This takes precedence over the include list. | list | “” | Comma-separated list of fields to exclude. | medium |
| Field rename mappings. For example, a nested field renaming list is | list | “” | Comma-separated list of colon-delimited renaming pairs, for example, | medium |
| Fields to include. If specified, only the named fields will be included in the resulting Struct or Map. | list | “” | Comma-separated list of fields to include. | medium |
| Specifies whether to replace null fields with their defined default values. When set to | boolean |
|
| medium |
| Special characters act as a delimiter. For example, a period (.) in | string | “.” | Any special character except a colon ( | medium |
Examples
These examples show how to configure and use ReplaceField to drop or rename a field.
The configuration snippet shows how to use ReplaceField transformation to exclude the dont field, and rename specific nested fields within the foo structure to xyz, bar, luck, and happy respectively.
"transforms": "ReplaceField",
"transforms.ReplaceField.type": "io.confluent.connect.transforms.ReplaceField$Value",
"transforms.ReplaceField.exclude": "dont",
"transforms.ReplaceField.renames": "foo.a2:xyz,foo:bar,foo.a3.b1:luck,foo.a3.b2.c1:happy"
This transforms the original message as shown:
Before:
{abc=42, etc=etc, foo={a1=k1, a2={b2={c1=f4}, b1={c1=f4}}, a3={b2={c1=f4}, b1={c1=f4}}}, dont=whatever}
After:
{etc=etc, bar={a1=k1, a3={b2={happy=f4}, luck={c1=f4}}, xyz={b2={c1=f4}, b1={c1=f4}}}, abc=42}
The configuration snippet shows how to use ReplaceField transformation to exclude the dont field, include only the foo.a3 field, and rename specific fields within the foo to xyz, bar, luck, and happy.
"transforms": "ReplaceField",
"transforms.ReplaceField.type": "io.confluent.connect.transforms.ReplaceField$Value",
"transforms.ReplaceField.exclude": "dont",
"transforms.ReplaceField.renames": "foo.a2:xyz,foo:bar,foo.a3.b1:luck,foo.a3.b2.c1:happy",
"transforms.ReplaceField.include": "foo.a3"
This transforms the original message as shown:
Before:
{abc=42, etc=etc, foo={a1=k1, a2={b2={c1=f4}, b1={c1=f4}}, a3={b2={c1=f4}, b1={c1=f4}}}, dont=whatever}
After:
{foo={a3={b2={happy=f4}, luck={c1=f4}}}}
The configuration snippet shows how to use ReplaceField transformation to exclude the dont field, include only the foo.a3.b2.c1 and foo.a2 fields, and rename specific fields within the foo to xyz, bar, luck, and happy.
"transforms": "ReplaceField",
"transforms.ReplaceField.type": "io.confluent.connect.transforms.ReplaceField$Value",
"transforms.ReplaceField.exclude": "dont",
"transforms.ReplaceField.renames": "foo.a2:xyz,foo:bar,foo.a3.b1:luck,foo.a3.b2.c1:happy",
"transforms.ReplaceField.include": "foo.a3.b2.c1,foo.a2"
This transforms the original message as shown:
Before:
{abc=42, etc=etc, foo={a1=k1, a2={b2={c1=f4}, b1={c1=f4}}, a3={b2={c1=f4}, b1={c1=f4}}}, dont=whatever}
After:
{foo={a3={b2={happy=f4}}, xyz={b2={c1=f4}, b1={c1=f4}}}}
The configuration snippet shows how to use ReplaceField transformation to exclude the dont, foo.a1, foo.a2.b2, foo.a3.b1.c1 fields, and rename specific fields within the foo to xyz, bar, luck, and happy.
"transforms": "ReplaceField",
"transforms.ReplaceField.type": "io.confluent.connect.transforms.ReplaceField$Value",
"transforms.ReplaceField.exclude": "dont,foo.a1,foo.a2.b2,foo.a3.b1.c1",
"transforms.ReplaceField.renames": "foo.a2:xyz,foo:bar,foo.a3.b1:luck,foo.a3.b2.c1:happy",
"transforms.ReplaceField.include": ""
This transforms the original message as shown:
Before:
{abc=42, etc=etc, foo={a1=k1, a2={b2={c1=f4}, b1={c1=f4}}, a3={b2={c1=f4}, b1={c1=f4}}}, dont=whatever}
After:
{etc=etc, bar={a3={b2={happy=f4}, luck={}}, xyz={b1={c1=f4}}}, abc=42}
The configuration snippet shows how to use ReplaceField transformation to only rename specific fields within the foo to xyz, bar, luck, and happy without excluding or including any fields.
"transforms": "ReplaceField",
"transforms.ReplaceField.type": "io.confluent.connect.transforms.ReplaceField$Value",
"transforms.ReplaceField.exclude": "",
"transforms.ReplaceField.renames": "foo.a2:xyz,foo:bar,foo.a3.b1:luck,foo.a3.b2.c1:happy",
"transforms.ReplaceField.include": ""
This transforms the original message as shown:
Before:
{abc=42, etc=etc, foo={a1=k1, a2={b2={c1=f4}, b1={c1=f4}}, a3={b2={c1=f4}, b1={c1=f4}}}, dont=whatever}
After:
{bar={a1=k1, a3={b2={happy=f4}, luck={c1=f4}}, xyz={b2={c1=f4}, b1={c1=f4}}}, abc=42, etc=etc, dont=whatever}
The configuration snippet shows how to use ReplaceField transformation to rename certain fields, while also specifying which fields to include or exclude. In the following example, only included fields should be subject to renaming and transformed in the final output.
"transforms": "ReplaceField",
"transforms.ReplaceField.type": "io.confluent.connect.transforms.ReplaceField$Value",
"transforms.ReplaceField.exclude": "foo.a1,foo.a2",
"transforms.ReplaceField.renames": "foo.a2:xyz,foo:bar,foo.a3.b1:luck,foo.a3.b2.c1:happy",
"transforms.ReplaceField.include": "foo.a2,foo.a3.b2.c1"
This transforms the original message as shown:
Before:
{abc=42, etc=etc, foo={a1=k1, a2={b2={c1=f4}, b1={c1=f4}}, a3={b2={c1=f4}, b1={c1=f4}}}, dont=whatever}
After:
{foo={a3={b2={happy=f4}}}}
Predicates
Configure transformations with predicates to ensure they process only records that satisfy a particular condition. You can also use predicates in a transformation chain with the Kafka Connect Filter (Kafka) SMT Usage Reference for Confluent Platform to conditionally filter specific records. For more information, see Predicates.
