MaskField

The following provides usage information for the Apache Kafka® SMT org.apache.kafka.connect.transforms.MaskField.

Description

Can be used for the following scenarios:

  • Mask specified fields with a valid null value for the field type (i.e. 0, false, empty string, and so on).
  • Replace any string or numeric field using the replacement property.

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

Examples

Mask value

This configuration snippet shows how to use MaskField to mask the value of a field.

"transforms": "MaskField",
"transforms.MaskField.type": "org.apache.kafka.connect.transforms.MaskField$Value",
"transforms.MaskField.fields": "string_field"

This masks string_field, transforming the original message as seen here:

{"integer_field":22, "string_field":"foo"}

into the result here:

{"integer_field":22, "string_field":""}

Replace value

This configuration snippet shows how to use MaskField to replace the value of a field. There are three transformations in the example. The first and second replace a value in a single field. The third is applied to both office and mobile phone number fields.

"transforms": "SSNMask", "IPMask", "PhoneMask",

"transforms.SSNMask.type": "org.apache.kafka.connect.transforms.MaskField$Value",
"transforms.SSNMask.fields": "SSN",
"transforms.SSNMask.replacement": "***-***-****",

"transforms.IPMask.type": "org.apache.kafka.connect.transforms.MaskField$Value",
"transforms.IPMask.fields": "IPAddress",
"transforms.IPMask.replacement": "xxx.xxx.xxx.xxx",

"transforms.PhoneMask.type": "org.apache.kafka.connect.transforms.MaskField$Value",
"transforms.PhoneMask.fields": "office,mobile",
"transforms.PhoneMask.replacement": "+0-000-000-0000"

Tip

For additional examples, see Mask Field for managed connectors.

Properties

Name Description Type Default Valid Values Importance
fields Names of fields to mask. list   non-empty list high
replacement Custom value replacement applied to all fields values. string null Non-empty string with a numeric or text value that can be converted to fields type(s). low

Predicates

Transformations can be configured with predicates so that the transformation is applied only to records which satisfy a condition. You can use predicates in a transformation chain and, when combined with the Filter (Apache Kafka), predicates can conditionally filter out specific records. For details and examples, see Predicates.