You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "zhangshenghang (via GitHub)" <gi...@apache.org> on 2026/04/09 06:56:29 UTC

[PR] [Fix][Connector-V2][MySQL] Preserve table comments, indexes, ENGINE, CHARSET, and COLLATE in auto-created tables [seatunnel]

zhangshenghang opened a new pull request, #10738:
URL: https://github.com/apache/seatunnel/pull/10738

   ### Purpose of this pull request
   
   Fixes #10736. When using the SeaTunnel JDBC connector for MySQL-to-MySQL data migration with `schema_save_mode = CREATE_SCHEMA_WHEN_NOT_EXIST`, the automatically created target tables were missing critical metadata compared to the source tables:
   
   - **Table comments** were not read because MySQL Connector/J's `DatabaseMetaData.getTables()` returns `null` for the `REMARKS` column unless `useInformationSchema=true` is set in the JDBC URL.
   - **Column comments** were already preserved correctly (via `INFORMATION_SCHEMA.COLUMNS`).
   - **Non-primary-key indexes** (INDEX_KEY, UNIQUE_KEY) were already supported in the code but the SQL builder produced invalid DDL for FOREIGN KEY constraints.
   - **ENGINE, CHARSET, COLLATE** were hardcoded to `null` in `MysqlCreateTableSqlBuilder`, so they were never included in generated DDL.
   
   ### Changes
   
   **MySqlCatalog.java**
   - Override `getTableComment()` to query `information_schema.tables.TABLE_COMMENT` directly instead of relying on `DatabaseMetaData.getTables()`.
   - Override `getTable(TablePath)` to enrich the returned `CatalogTable`'s options map with ENGINE, CHARSET, and COLLATE read from `information_schema.tables`.
   
   **MysqlCreateTableSqlBuilder.java**
   - Read ENGINE, CHARSET, and COLLATE from `CatalogTable.getOptions()` instead of hardcoding `null`.
   - Fix `buildConstraintKeySql()`: skip FOREIGN KEY generation (returns `null`) since `ConstraintKey` does not carry referenced table/column info, avoiding invalid DDL.
   - Add VECTOR_INDEX_KEY case to skip generation (MySQL 8.0+ specific).
   
   **JdbcMySqlSaveModeCatalogIT.java (E2E)**
   - Add table comment, ENGINE, CHARSET, COLLATE, and non-PK indexes to the source table definition.
   - Add assertions verifying all metadata (table comment, column comment, ENGINE, CHARSET, COLLATE, indexes) are preserved in the sink table created via `Catalog.createTable()`.
   - Add SQL-level verification via `information_schema.tables` and `SHOW INDEX`.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. After this fix, when using the JDBC MySQL connector with catalog-based schema creation (e.g., `table_path` config or `JdbcCatalogUtils`), the auto-created tables will now include:
   - Table comments from the source table
   - ENGINE (e.g., InnoDB)
   - DEFAULT CHARSET
   - COLLATE
   - Non-primary-key indexes (INDEX_KEY, UNIQUE_KEY)
   
   Previously these were silently dropped.
   
   ### How was this patch tested?
   
   - Unit tests: `MysqlCreateTableSqlBuilderTest` passes (2 tests).
   - E2E test: `JdbcMySqlSaveModeCatalogIT.testCatalog()` enhanced with assertions for table comment, ENGINE, CHARSET, COLLATE, and non-PK indexes.
   - Manual verification: compiled with `./mvnw -DskipTests verify`.
   
   ### Check list
   
   - [x] Code follows Google Java Format (spotless:apply applied)
   - [x] No new dependencies introduced
   - [ ] E2E test will be validated by CI (requires MySQL container)
   - [x] Only modifies MySQL connector, no changes to OceanBase MySQL connector


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Fix][Connector-V2][MySQL] Preserve table comments, indexes, ENGINE, CHARSET, and COLLATE in auto-created tables [seatunnel]

Posted by "davidzollo (via GitHub)" <gi...@apache.org>.
davidzollo merged PR #10738:
URL: https://github.com/apache/seatunnel/pull/10738


-- 
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: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org