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

Open
wants to merge 6 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.

// 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.

@github-actions github-actions bot removed the base label Dec 12, 2024
@lvyanquan
Copy link
Contributor

Hi, @MOBIN-F. Is there any blocker for this being ready?

@MOBIN-F MOBIN-F marked this pull request as ready for review February 20, 2025 03:10
@MOBIN-F MOBIN-F force-pushed the release-support-debezium-json-include-schema branch from 1a2f93e to b7632e6 Compare February 28, 2025 10:53
case VARCHAR:
case VARBINARY:
default:
field = SchemaBuilder.string();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This includes ARRAY/MAP/ROW, There may be some issues if all they were converted to SchemaBuilder.string.
You can check if there is a better type, and if not, it is also acceptable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debezium-json does not seem to receive ARRAY/MAP/ROW type data because the mysql does not support this type

@lvyanquan
Copy link
Contributor

Thanks @MOBIN-F for this update.
Overall, This modification is good for me, left some comments about the code structure.

Additionally, you can manually test the data types in Paimon action to verify its correctness.

@github-actions github-actions bot added the docs Improvements or additions to documentation label Mar 5, 2025
<div class="wy-table-responsive">
<table class="colwidths-auto docutils">
<thead>
<tr>
<th class="text-left">CDC type</th>
<th class="text-left">JSON type</th>
<th class="text-left">Literal type</th>
<th class="text-left">Semantic type</th>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add Literal/Semantic type to the documentation? It seems like users won't care about it? @lvyanquan

Copy link
Contributor

@lvyanquan lvyanquan Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I suggest not add this as users won't pay much attention on it.

I think adding more information is not a disadvantage, so we can keep them.

@MOBIN-F
Copy link
Contributor Author

MOBIN-F commented Mar 5, 2025

Thanks @MOBIN-F for this update. Overall, This modification is good for me, left some comments about the code structure.

Additionally, you can manually test the data types in Paimon action to verify its correctness.

I tested 【pipeline-kafka-->kafka-->paimon action->paimon table】, and it worked as expected. Maybe I can add some e2e tests later.

Copy link
Contributor

@lvyanquan lvyanquan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Left some minor comments.

@github-actions github-actions bot removed the reviewed label Mar 12, 2025
Copy link
Contributor

@lvyanquan lvyanquan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@lvyanquan
Copy link
Contributor

Hi @leonardBang @ruanhang1993 could you help to check about this?

Copy link
Contributor

@leonardBang leonardBang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @MOBIN-F and @lvyanquan for the contribution, LGTM, wait the CI green

@MOBIN-F
Copy link
Contributor Author

MOBIN-F commented Mar 14, 2025

CI failed, but it has nothing to do with this PR because this PR only involves the kafka-pipeline module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants