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

feat(source): support kafka-connect schema guided debezium parsing #16852

Open
fuyufjh opened this issue May 21, 2024 · 0 comments
Open

feat(source): support kafka-connect schema guided debezium parsing #16852

fuyufjh opened this issue May 21, 2024 · 0 comments
Assignees

Comments

@fuyufjh
Copy link
Member

fuyufjh commented May 21, 2024

When consuming from debezium, the unit info is actually available as part of the schema:

We will focus on the second case here. Below is a message from debezium 2.4 MySQL connector:

{
  "schema": {
    "type": "struct",
    "fields": [
      {
        "type": "struct",
        "fields": [
          {
            "type": "int32",
            "optional": true,
            "field": "bid"
          },
          {
            "type": "int64",
            "optional": true,
            "name": "io.debezium.time.MicroTimestamp",
            "version": 1,
            "field": "at"
          }
        ],
        "optional": true,
        "name": "dbserver1.inventory.bar.Value",
        "field": "before"
      },
      {
        "type": "struct",
        "fields": [
          {
            "type": "int32",
            "optional": true,
            "field": "bid"
          },
          {
            "type": "int64",
            "optional": true,
            "name": "io.debezium.time.MicroTimestamp",
            "version": 1,
            "field": "at"
          }
        ],
        "optional": true,
        "name": "dbserver1.inventory.bar.Value",
        "field": "after"
      },
      {
        "type": "struct",
        "fields": [
          {
            "type": "string",
            "optional": false,
            "field": "version"
          },
          {
            "type": "string",
            "optional": false,
            "field": "connector"
          },
          {
            "type": "string",
            "optional": false,
            "field": "name"
          },
          {
            "type": "int64",
            "optional": false,
            "field": "ts_ms"
          },
          {
            "type": "string",
            "optional": true,
            "name": "io.debezium.data.Enum",
            "version": 1,
            "parameters": {
              "allowed": "true,last,false,incremental"
            },
            "default": "false",
            "field": "snapshot"
          },
          {
            "type": "string",
            "optional": false,
            "field": "db"
          },
          {
            "type": "string",
            "optional": true,
            "field": "sequence"
          },
          {
            "type": "string",
            "optional": true,
            "field": "table"
          },
          {
            "type": "int64",
            "optional": false,
            "field": "server_id"
          },
          {
            "type": "string",
            "optional": true,
            "field": "gtid"
          },
          {
            "type": "string",
            "optional": false,
            "field": "file"
          },
          {
            "type": "int64",
            "optional": false,
            "field": "pos"
          },
          {
            "type": "int32",
            "optional": false,
            "field": "row"
          },
          {
            "type": "int64",
            "optional": true,
            "field": "thread"
          },
          {
            "type": "string",
            "optional": true,
            "field": "query"
          }
        ],
        "optional": false,
        "name": "io.debezium.connector.mysql.Source",
        "field": "source"
      },
      {
        "type": "string",
        "optional": false,
        "field": "op"
      },
      {
        "type": "int64",
        "optional": true,
        "field": "ts_ms"
      },
      {
        "type": "struct",
        "fields": [
          {
            "type": "string",
            "optional": false,
            "field": "id"
          },
          {
            "type": "int64",
            "optional": false,
            "field": "total_order"
          },
          {
            "type": "int64",
            "optional": false,
            "field": "data_collection_order"
          }
        ],
        "optional": true,
        "name": "event.block",
        "version": 1,
        "field": "transaction"
      }
    ],
    "optional": false,
    "name": "dbserver1.inventory.bar.Envelope",
    "version": 1
  },
  "payload": {
    "before": null,
    "after": {
      "bid": 8,
      "at": 1712132700123457
    },
    "source": {
      "version": "2.4.2.Final",
      "connector": "mysql",
      "name": "dbserver1",
      "ts_ms": 1712132719000,
      "snapshot": "false",
      "db": "inventory",
      "sequence": null,
      "table": "bar",
      "server_id": 223344,
      "gtid": null,
      "file": "mysql-bin.000003",
      "pos": 3181,
      "row": 0,
      "thread": 8,
      "query": null
    },
    "op": "c",
    "ts_ms": 1712132719617,
    "transaction": null
  }
}

The relevant part is here:

      {
        "type": "struct",
        "fields": [
          {
            "type": "int32",
            "optional": true,
            "field": "bid"
          },
          {
            "type": "int64",
            "optional": true,
            "name": "io.debezium.time.MicroTimestamp",
            "version": 1,
            "field": "at"
          }
        ],
        "optional": true,
        "name": "dbserver1.inventory.bar.Value",
        "field": "after"
      },

and

    "after": {
      "bid": 8,
      "at": 1712132700123457
    },

Note the field after.at has "type": "int64" and "name": "io.debezium.time.MicroTimestamp"

The structure of this schema field is actually from Java class org.apache.kafka.connect.json.JsonConverter:
https://github.com/apache/kafka/blob/3.7.0/connect/json/src/main/java/org/apache/kafka/connect/json/JsonConverter.java#L313

Originally posted by @xiangjinwu in #16097 (comment)

@github-actions github-actions bot added this to the release-1.10 milestone May 21, 2024
@xiangjinwu xiangjinwu self-assigned this May 21, 2024
@xiangjinwu xiangjinwu changed the title bug: parse timestamp correctly feat: support kafka-connect schema guided parsing May 21, 2024
@xiangjinwu xiangjinwu changed the title feat: support kafka-connect schema guided parsing feat(source): support kafka-connect schema guided debezium parsing May 21, 2024
@xiangjinwu xiangjinwu modified the milestones: release-1.10, release-1.11 Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants