【发布时间】:2019-06-15 14:35:56
【问题描述】:
用例是将整个消息(即 JSON)和键存储为表中的记录,该表具有两列“id”和“data”。
数据库为 Postgres,支持 JSON 列类型。
根据本文,JSONConverter 中支持的类型是字符串、int64 等 https://cwiki.apache.org/confluence/display/KAFKA/KIP-301%3A+Schema+Inferencing+for+JsonConverter
是否可以将数据字段类型为 JSON,然后可以将其存储在 Postgres DB 中,列类型为 JSON。
schema = `{
"type":"struct",
"fields":[
{"type":"string", "optional": false, "field":"id"},
{"type":"string", "optional": false, "field":"data"}
]}`
样本数据有效载荷是
"payload": { "id": 10000, "data": {"hello":"world"} }
Above 将数据存储为文本,并期望列在 Postgres 中为文本类型。 如果 Postgres 上的列是 JSON 类型,那么 JDBC Sink 连接器将抛出错误。
在 Postgres 上使用 JSON 类型将有助于在 JSON 字段等上创建索引。是否可以适当地使用 JSONConverter 和 JDBC Sink Converter 来存储列类型为 JSON 的记录。
【问题讨论】:
-
JDBC Sink Connector 抛出什么错误?你能添加一些日志吗?
标签: postgresql jdbc apache-kafka apache-kafka-connect confluent-platform