yzeng1618 opened a new pull request, #11971:
URL: https://github.com/apache/seatunnel/pull/11971
### Purpose of this pull request
Fix #11969 (same root cause as the historical report #8329).
When a JDBC source table is defined by `query` only, the schema is derived
from JDBC `ResultSetMetaData`, which carries no column/table comments,
constraint keys or partition keys. Sinks that auto-create tables (Doris,
StarRocks, MySQL, ...) therefore create tables without any comments.
This PR resolves the underlying physical table from the query result
metadata when the query maps to a single table (e.g. `SELECT * FROM db.table`),
and merges the missing metadata (column/table comments, primary key, constraint
keys, partition keys, table options) into the query-derived table by reusing
the existing `mergeCatalogTable` logic — the same behavior as configuring
`table_path` together with `query`.
The merge is defensive:
- Applied in both the catalog path and the no-catalog fallback path, only
when the underlying table can be resolved and exists with a non-empty schema;
- Columns renamed or transformed in the query keep the query-derived
definition (`mergeCatalogTable` guards by column name + SqlType);
- Any failure loading the underlying table falls back to the current
query-derived behavior.
### Does this PR introduce _any_ user-facing change?
Yes. When a JDBC source uses `query` without `table_path` and the query maps
to a single existing table, the produced catalog table now carries the comments
/ primary key / constraint keys / partition keys of that table, so sinks with
auto table creation preserve them; previously they were silently lost. The Jdbc
source documentation (en/zh) is updated accordingly.
### How was this patch tested?
- New unit tests in `JdbcCatalogUtilsTest` covering: resolvable single-table
query (metadata merged), unresolvable table name, database/schema missing,
underlying table not existing, underlying table with empty schema, and loader
failure fallback.
- Extended `JdbcMysqlTableOptionsIT`, whose job config is exactly a
query-only MySQL-to-MySQL auto-create scenario: the source table now declares
column comments and a table comment, and the IT asserts they are present in
`SHOW CREATE TABLE` of the auto-created sink table.
### Check list
* [ ] If any new Jar binary package adding in your PR, please add License
Notice according
[New License
Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/developer/new-license.md)
* [x] If necessary, please update the documentation to describe the new
feature. https://github.com/apache/seatunnel/tree/dev/docs
* [ ] If necessary, please update `incompatible-changes.md` to describe the
incompatibility caused by this 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]