-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FLINK-36611][pipeline-connector][kafka] Add schema info to output of Kafka sink #3791
base: master
Are you sure you want to change the base?
[FLINK-36611][pipeline-connector][kafka] Add schema info to output of Kafka sink #3791
Conversation
after, | ||
meta, | ||
extractBeforeAndAfterSchema( | ||
jsonConverter.asJsonSchema(valueSchema)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Through the jsonConverter.asJsonSchema(valueSchema) method, we can easily obtain the complete schema json information of debezium-json.
At first, I wanted to convert the schema josn to GenericRowData, but the schema structure of debezium is too complex and difficult to implement.
Finally, I chose to pass the schema json information as a string to the downstream, which can reduce some serialization and deserialization overhead
// escape characters such as "\" | ||
String schemaValue = node.get("schema").asText(); | ||
JsonNode schemaNode = mapper.readTree(schemaValue); | ||
node.set("schema", schemaNode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the schema is passed to the downstream as a string, and there is a nested json in the schema, if the json string is put into jsonNode, there will be ["]. The JsonNode.asText() method can solve this problem well.
…ezium-json-include-schema # Conflicts: # flink-cdc-connect/flink-cdc-source-connectors/flink-cdc-base/src/test/java/org/apache/flink/cdc/connectors/base/MySqlSourceMetricsTest.java # flink-cdc-connect/flink-cdc-source-connectors/flink-cdc-base/src/test/java/org/apache/flink/cdc/connectors/base/source/MySqlEventDeserializer.java
Currently, the output of Kafka sink in debezium format looks like this:
It contains record data with full before/after and db info, but schema info wasn't included.
However, In some scenarios, we need this information to determine the type of data. For example, Paimon's Kafka CDC source requires this type information, otherwise all types are considered String, refer to https://paimon.apache.org/docs/0.9/flink/cdc-ingestion/kafka-cdc/#supported-formats.
Considering that this will increase the data load, I suggest adding a parameter to configure whether to enable it.