Skip to content
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

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

MOBIN-F
Copy link
Contributor

@MOBIN-F MOBIN-F commented Dec 11, 2024

Currently, the output of Kafka sink in debezium format looks like this:

{
  "before": {
    "id": 4,
    "name": "John",
    "address": "New York",
    "phone_number": "2222",
    "age": 12
  },
  "after": {
    "id": 4,
    "name": "John",
    "address": "New York",
    "phone_number": "1234",
    "age": 12
  },
  "op": "u",
  "source": {
    "db": null,
    "table": "customers"
  }
} 

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.

after,
meta,
extractBeforeAndAfterSchema(
jsonConverter.asJsonSchema(valueSchema))))
Copy link
Contributor Author

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);
Copy link
Contributor Author

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
@github-actions github-actions bot removed the base label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant