Kafka Connect ExtractNewRecordState (Debezium) SMT Usage Reference for Confluent Cloud
The ExtractNewRecordState SMT (io.debezium.transforms.ExtractNewRecordState)
flattens Debezium change events by replacing the event envelope with the row
state after the change.
Description
Debezium change events use a nested envelope with before, after,
source, op, and ts_ms fields. Use this SMT when downstream
consumers or sink connectors require a flat record instead of the envelope.
In addition to unwrapping the after state, you can configure this SMT to:
Control how delete events and tombstones are emitted.
Copy change event metadata into the record value or headers.
Replace null column values with their column default values.
For complete details, see the official Debezium New Record State Extraction documentation. For the full list of available SMTs, see Kafka Connect Single Message Transformation Reference for Confluent Cloud.
Note
When using this SMT, consider the following:
Place this SMT after SMTs that read the change event envelope, such as ExtractChangedRecordState, and before SMTs that operate on the flattened row fields. The record key and headers set by earlier SMTs, such as ToLogicalTopicRouter, are preserved.
Don’t use
unwrapas the transform alias for the managed Debezium change data capture (CDC) Source connectors. The connector reserves this alias forafter.state.only. For details, see Transform alias validation.If you set
after.state.onlytotrue, the connector already flattens records, so the options of this SMT have no effect. Setafter.state.onlytofalseto configure this SMT.replace.null.with.defaultapplies only to columns that have a default value defined in the source database. Null values in columns without a default remain null.
Limitations
The ExtractNewRecordState SMT is available only for the Oracle XStream CDC
Source connector and for managed Debezium CDC Source connectors, such as
PostgreSQL, MySQL, SQL Server, and MariaDB.
For the Oracle XStream CDC Source connector, after.state.only doesn’t
flatten records, and the unwrap alias isn’t reserved. To flatten records,
add this SMT to the connector configuration.
Properties
The following table lists the configuration options for the
ExtractNewRecordState SMT.
Name |
Description |
Type |
Default |
Importance |
|---|---|---|---|---|
|
How to handle delete events and tombstones. Accepts |
string |
medium |
|
|
Deprecated. Use |
string |
|
medium |
|
Deprecated. Use |
boolean |
|
low |
|
The name of a field in the row state whose value replaces the record’s topic name. |
string |
low |
|
|
A comma-separated list of change event metadata fields, such as |
list |
low |
|
|
The prefix added to the names of fields added by |
string |
|
low |
|
A comma-separated list of change event metadata fields to add to the record headers. |
list |
low |
|
|
The prefix added to the names of headers added by |
string |
|
low |
|
Whether to replace a null column value with the default value defined for the column in the source database. |
boolean |
|
low |
Example
The following example flattens change events, rewrites delete events with a
__deleted field, and adds the operation type to the record value. The
example assumes that after.state.only is false, if the connector has
that property.
"transforms": "flatten",
"transforms.flatten.type": "io.debezium.transforms.ExtractNewRecordState",
"transforms.flatten.delete.tombstone.handling.mode": "rewrite",
"transforms.flatten.add.fields": "op"
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 Kafka Connect Filter (Kafka) SMT Usage Reference for Confluent Cloud, predicates can conditionally filter out specific records. For details and examples, see Predicates.