hutiefang76 opened a new pull request, #12425:
URL: https://github.com/apache/seatunnel/pull/12425
### Purpose of this pull request
Fixes #12415.
When `generate_sink_sql` creates a MySQL target table, nullable source
metadata could make a configured primary-key column render as `NULL`. MySQL
rejects that DDL because every primary-key column must be `NOT NULL`.
The MySQL and OceanBase MySQL-mode builders now render a column as `NOT
NULL` when `create_index` is enabled and that column belongs to the resolved
primary key. Non-key nullable columns remain `NULL`, and disabling
`create_index` preserves the previous nullable-column output.
### Does this PR introduce _any_ user-facing change?
Yes. JDBC sinks that auto-create MySQL or OceanBase MySQL-mode target tables
can now use nullable source metadata for configured primary-key columns. The
generated target DDL declares those key columns `NOT NULL`, allowing table
creation to succeed.
### How was this patch tested?
- Red baseline: the new MySQL and OceanBase tests each failed before the
production change because generated DDL contained `NULL` for the nullable
primary-key column.
- Green validation under JDK 8:
`env
JAVA_HOME=/Users/hutiefang/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home
./mvnw -s /private/tmp/seatunnel-empty-settings.xml --no-snapshot-updates
--batch-mode -pl seatunnel-connectors-v2/connector-jdbc -am
-Dtest=MysqlCreateTableSqlBuilderTest,OceanBaseMysqlCreateTableSqlBuilderTest
-Dsurefire.failIfNoSpecifiedTests=false package`
completed successfully. `MysqlCreateTableSqlBuilderTest` ran 5 tests and
`OceanBaseMysqlCreateTableSqlBuilderTest` ran 2 tests, with no failures or
errors.
- The new tests also assert that non-key nullable columns remain `NULL`,
while disabling `create_index` leaves the primary-key metadata column nullable
and emits no `PRIMARY KEY` clause.
- `git diff --check` passed.
This change was prepared with OpenAI Codex assistance. Please review the
code and validation evidence through the normal project process.
### Check list
* [ ] No new Jar binary package is added.
* [ ] No documentation update is needed because the existing `primary_keys`
contract is unchanged; this fixes invalid generated DDL.
* [ ] No incompatible change is introduced.
* [x] Connector unit tests cover the MySQL and OceanBase MySQL-mode DDL
builders.
--
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]