Kafka Connect TimestampConverter SMT Usage Reference for Confluent Platform

The TimestampConverter SMT (org.apache.kafka.connect.transforms.TimestampConverter) converts record timestamps between various formats, including Unix epoch integers, formatted strings, and Connect’s native Date or Timestamp types.

Description

This SMT applies to an individual field or to the entire value.

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

Note

The TimestampConverter SMT operates on one field at a time.

For timestamp-based topic routing, see Kafka Connect TimestampRouter SMT Usage Reference for Confluent Platform and Kafka Connect MessageTimestampRouter SMT Usage Reference for Confluent Platform.

Properties

Name

Description

Type

Default

Valid values

Importance

target.type

The target format for the converted timestamp.

string

string, unix, Date, Time, Timestamp

high

field

The specific field name to convert. If left empty, the entire record value is treated as the timestamp.

string

“”

high

format

The java.text.SimpleDateFormat pattern used to parse or generate string timestamps. For more details, see SimpleDateFormat.

string

“”

medium

unix.precision

The desired Unix precision for the timestamp in seconds, milliseconds, microseconds, or nanoseconds. Converting values using microseconds or nanoseconds can cause precision loss.

string

milliseconds

seconds, milliseconds, microseconds, nanoseconds

low

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

Convert a Unix epoch to a date string

This configuration snippet shows how to use TimestampConverter to transform a Unix epoch (represented as an int64 value) into a formatted date string.

"transforms": "TimestampConverter",
"transforms.TimestampConverter.type": "org.apache.kafka.connect.transforms.TimestampConverter$Value",
"transforms.TimestampConverter.format": "yyyy-MM-dd",
"transforms.TimestampConverter.target.type": "string"

Before: 1696521093

After: "2023-10-05"

Set the converter precision to microseconds

This configuration snippet shows how to use TimestampConverter to define the converter precision to microseconds. Converting values using microseconds or nanoseconds can cause precision loss.

"transforms.TimestampConverter.type": "org.apache.kafka.connect.transforms.TimestampConverter$Value",
"transforms.TimestampConverter.field": "event_date_long",
"transforms.TimestampConverter.unix.precision": "microseconds",
"transforms.TimestampConverter.target.type": "Timestamp"

Before: 1696521093

After: 1696521093000000

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.