问题描述
我正在通过Kafka connect将Debezium连接器用于Postgres。
对于由连接器写入Kafka的插入行事件,我需要有关哪些列是主键而哪些列不是主键的信息。有办法实现吗?
粘贴在Kafka中生成的示例插入事件:
"schema": {
"type": "struct","fields": [
{
"type": "struct","fields": [
{
"type": "int32","optional": false,"field": "id"
},{
"type": "int32","field": "bucket_type"
}
],"optional": true,"name": "postgresconfigdb.config.alert_configs.Value","field": "before"
},{
"type": "struct","field": "after"
},"fields": [
{
"type": "string","field": "version"
},{
"type": "string","field": "connector"
},"field": "name"
},{
"type": "int64","field": "ts_ms"
},"name": "io.debezium.data.Enum","version": 1,"parameters": {
"allowed": "true,last,false"
},"default": "false","field": "snapshot"
},"field": "db"
},"field": "schema"
},"field": "table"
},"field": "txId"
},"field": "lsn"
},"field": "xmin"
}
],"name": "io.debezium.connector.postgresql.source","field": "source"
},{
"type": "string","field": "op"
},{
"type": "int64","field": "ts_ms"
},"field": "total_order"
},"field": "data_collection_order"
}
],"field": "transaction"
}
],"name": "postgresconfigdb.config.alert_configs.Envelope"
},"payload": {
"before": null,"after": {
"id": 1100,"bucket_type": 10
},"source": {
"version": "1.2.0.Final","connector": "postgresql","name": "postgresconfigdb","ts_ms": 1599830887858,"snapshot": "true","db": "configdb","schema": "config","table": "alert_configs","txId": 2139888,"lsn": 379356048,"xmin": null
},"op": "r","ts_ms": 1599830887859,"transaction": null
}
}
这里表中的列是'id'和'bucket_type',其值在json-path负载->之后报告。
在特定于列的“可选”布尔字段中有关于不为空的列的信息,但是没有关于哪些列是主键的信息。 (在这种情况下为id)
解决方法
您可以找到有关Kafka键中哪些字段是PK列的信息。