在jdbc-sink-connector中使用kafka SMT将avro模式中的Map字段转换为字符串?

时间:2018-09-16 06:56:34

标签: apache-kafka apache-kafka-connect

我有一个定义如下的avro模式:

[    
{
    "namespace": "com.fun.message",
    "type": "record",
    "name": "FileData",
    "doc": "Avro Schema for FileData",
    "fields": [
        {"name": "id", "type": "string", "doc": "Unique file id" },
        {"name": "absolutePath", "type": "string", "doc": "Absolute path of file" },
        {"name": "fileName", "type": "string", "doc": "File name" },
        {"name": "source", "type": "string", "doc": "unique identification of source" },
        {"name": "metaData", "type": {"type": "map", "values": "string"}}
    ]
}
]

我想使用jdbc-sink-connector将数据推送到postgres,以便可以将架构中的"metaData"字段(映射类型)转换为字符串。我该怎么做呢?

1 个答案:

答案 0 :(得分:1)

您需要使用SMT和AFAIK,目前还没有一种SMT可以完全满足您的要求(ExtractFieldMap.get操作,因此不能一次提取嵌套字段)。您可以看一下Debezium的io.debezium.transforms.UnwrapFromEnvelope SMT,可以对其进行修改以提取嵌套字段。

UnwrapFromEnvelope用于CDC Event Flattening的目的是从更复杂的结构中提取字段,例如Debezium形成的数据(我认为这与您的结构相似)。