fix(kingbase): export table DDL from catalog metadata - #2879
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issue
N/A - this fix follows a direct error report. No matching open issue was found.
Summary
Exporting a Kingbase table's DDL fails with
column c.udt_name does not existwheninformation_schema.columnsomits PostgreSQL-style fields. Read column metadata from the system catalogs and useformat_typeandpg_get_exprto retain complete type definitions and expressions.Detect optional identity and generated-column attributes from JDBC result metadata. Preserve identity generation mode and sequence options, quote column names, and retain the column-privilege filter. For MySQL-compatible Kingbase builds, use the same reconstruction rules as
sys_dump: attachAUTO_INCREMENTafter keys, restore the sequence'slast_value,next_valueandis_calledstate, and declare attached enums withENUM ... NAMES ...so their defaults remain valid. Existing comment escaping and ownership/grant output are retained. Add eight regression tests covering these cases and the original catalog compatibility behavior.Affected surfaces
Verification
KingbaseES_V009R003C018B0003_aarch64_Docker.tarimage locally and confirmedKingbaseES V009R003C018,database_mode=mysql. Used the repository's defaultkingbase8-8.6.0.jardriver and directly invoked the PR's compiledKingBaseMetaData.tableDDL. Reproduced the original missing-udt_nameerror. Seven integration scenarios passed export/recreation and data or metadata checks: ordinary columns/defaults/precision, auto-increment, stored generated columns, an unusedAUTO_INCREMENT=3000000000starting value, enum defaults, arrays, and quoted column names/comments/indexes/grants. Test schemas, roles and attached enum types were removed; all three leftover counts were zero.KingbaseES_V009R001C010B0004_aarch64_Docker.tarimage and confirmedKingbaseES V009R001C010,database_mode=pg. Direct invocation of the unchanged PR'sKingBaseMetaData.tableDDLwith the default Kingbase JDBC driver passed eight integration scenarios: ordinary columns/defaults/precision, ALWAYS identity with a 3000000000 start and nondefault sequence options, BY DEFAULT identity with a 5000000000 start, arrays, schema-qualified PostgreSQL enums, domain-typed columns, stored generated columns, and quoted names/comments/indexes/grants. Each scenario recreated the table from the exported DDL and checked metadata and inserts. Explicit values were rejected for ALWAYS identity and accepted for BY DEFAULT identity; domain NOT NULL remained enforced. PostgreSQL enums did not use the MySQLNAMESclause. Cleanup left zero test schemas or roles.VIRTUALgenerated-column syntax when creating a fixture; that scenario is explicitly not counted as an integration pass.Risk and compatibility
V009R003C018in MySQL mode andV009R001C010in PG mode, both with the configured default JDBC driver. The exact reportedV009R003C011PS021patch build remains untested.attidentityorattgeneratedremain supported. Identity sequence lookup is only performed for identity columns; unavailable sequence metadata raises an error instead of silently changing the definition.Reviewer map
SqlConstant.COLUMN_SQL,IDENTITY_SEQUENCE_SQLandSEQUENCE_STATE_SQL, thenKingBaseMetaData.tableDDL,appendIdentityOptionsandappendAutoIncrement; regression coverage is inKingBaseTableDDLTest.udt_name; also verify complete type/default/identity definitions on the target Kingbase version.Contributor declaration
AI assistance: Codex implemented the change, added regression tests, reviewed the diff, and ran the reported verification. Real Kingbase V9R3C18 MySQL mode, V9R1C10 PG mode, and PostgreSQL 17 verification is described above; the exact reported patch build remains unverified.