Kafka Connect ReplaceField SMT Usage Reference for Confluent Platform

The ReplaceField SMT (org.apache.kafka.connect.transforms.ReplaceField) filters or renames fields within an Apache Kafka® record’s Struct or Map.

Description

Filter or rename fields within a Struct or Map.

Use the concrete transformation type designed for the record key (org.apache.kafka.connect.transforms.ReplaceField$Key) or value (org.apache.kafka.connect.transforms.ReplaceField$Value).

For the Confluent version that also supports nested fields, see ReplaceField (Confluent).

Properties

Name

Description

Type

Default

Valid values

Importance

exclude

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

renames

Field rename mappings.

list

“”

Comma-separated list of colon-delimited renaming pairs, for example, foo:bar,abc:xyz.

medium

include

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

replace.null.with.default

Specifies whether to replace null fields with their defined default values. When set to true, the default value is applied. Otherwise, the field remains null.

boolean

true

true or false

medium

Examples

These examples show how to configure and use ReplaceField.

Drop a field

This configuration snippet shows how to use ReplaceField to exclude a field and remove it.

"transforms": "ReplaceField",
"transforms.ReplaceField.type": "org.apache.kafka.connect.transforms.ReplaceField$Value",
"transforms.ReplaceField.exclude": "c2"

This removes c2, transforming the original message as shown here:

{"c1":22,"c2":"foo"}

to this result:

{"c1":22}

Rename a field

This configuration snippet shows how to use ReplaceField with the renames property.

"transforms": "RenameField",
"transforms.RenameField.type": "org.apache.kafka.connect.transforms.ReplaceField$Value",
"transforms.RenameField.renames": "foo:c1,bar:c2"

This replaces the foo and bar field names with c1 and c2.

Before: {"foo":22,"bar":"baz"}

After: {"c1":22,"c2":"baz"}

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.