CodeWithPravinMaske opened a new issue, #12599:
URL: https://github.com/apache/seatunnel/issues/12599

   ### Search before asking
   
   - [x] I had searched in the issues and found no similar issues.
   
   ### What happened
   
   For a MySQL table **without a primary key** that has a **nullable `UNIQUE 
KEY`** column, MySQL-CDC emits `0` instead of `NULL` for that column. Verified 
for binlog events on `dev`; the same conversion also applies to snapshot rows 
(observed once the snapshot split fix from #12598 lets those rows be read). 
This is silent data corruption: the sink receives `0` and no error is reported.
   
   Cause: Debezium 1.9.8, used to parse the table DDL 
(`MySqlSchema#parseSnapshotDdl`), promotes the first `UNIQUE KEY` of a table 
without a primary key to a primary key and marks its columns NOT NULL 
(`CreateTableParserListener#enterUniqueKeyTableConstraint` -> 
`MySqlAntlrDdlParser#parsePrimaryIndexColumnNames`, which does 
`column.edit().optional(false)` with the comment "MySQL does not allow a 
primary key to have nullable columns"). The value conversion then treats the 
column as not optional and turns NULL into the type default `0`.
   
   ### How to reproduce (MySQL 8.0, verified on `dev`)
   
   ```sql
   CREATE TABLE shop.no_pk_orders (
     id   INT NOT NULL,
     code INT NULL,
     name VARCHAR(32),
     UNIQUE KEY uk_code (code)
   );
   ```
   
   Run a MySQL-CDC job on `shop.no_pk_orders` with a Console sink 
(`exactly_once = false`), then:
   
   ```sql
   INSERT INTO shop.no_pk_orders (id, code, name) VALUES (5001, NULL, 
'live-null-row'), (5002, 5002, 'live-normal-row');
   ```
   
   Console output:
   
   ```
   SeaTunnelRow#kind=INSERT : 5001, 0, live-null-row      <-- expected 5001, 
null, live-null-row
   SeaTunnelRow#kind=INSERT : 5002, 5002, live-normal-row
   ```
   
   ### Expected behavior
   
   NULL values are emitted as NULL. The column nullability should follow the 
database (for example `SHOW CREATE TABLE` / JDBC metadata), not the promoted 
primary key.
   
   ### Related
   
   Found together with #12598, which has the same root cause but a different 
symptom (rows skipped by the snapshot).
   
   ### SeaTunnel Version
   
   dev (3.0.0-SNAPSHOT)
   
   ### Are you willing to submit a PR?
   
   - [x] Yes I am willing to submit a PR!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to