Skip to content

fix(kingbase): export table DDL from catalog metadata - #2879

Merged
openai0229 merged 3 commits into
mainfrom
fix/kingbase-ddl-catalog-metadata
Sep 7, 2026
Merged

openai0229 merged 3 commits into
mainfrom
fix/kingbase-ddl-catalog-metadata

Conversation

@openai0229

@openai0229 openai0229 commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

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 exist when information_schema.columns omits PostgreSQL-style fields. Read column metadata from the system catalogs and use format_type and pg_get_expr to 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: attach AUTO_INCREMENT after keys, restore the sequence's last_value, next_value and is_called state, and declare attached enums with ENUM ... 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

  • Frontend / Web
  • Backend / API / Storage
  • Database plugin / Driver
  • JCEF / Desktop packaging
  • CI / Build / Release
  • Documentation only

Verification

  • Commands and results: Java 17, run in the isolated PR worktree; 27 tests passed, zero failures/errors/skips, and the plugin plus reactor dependencies packaged successfully.
mvn -B -f chat2db-community-server/pom.xml \
  -pl :chat2db-community-kingbase -am \
  -Dmaven.test.skip=false -DskipTests=false \
  -Dtest=KingBaseTableDDLTest,KingBaseSQLIdentifierProcessorTest \
  -Dsurefire.failIfNoSpecifiedTests=false \
  -Dmaven.test.failure.ignore=false package
git diff --check
  • Manual verification: Deployed the official KingbaseES_V009R003C018B0003_aarch64_Docker.tar image locally and confirmed KingbaseES V009R003C018, database_mode=mysql. Used the repository's default kingbase8-8.6.0.jar driver and directly invoked the PR's compiled KingBaseMetaData.tableDDL. Reproduced the original missing-udt_name error. Seven integration scenarios passed export/recreation and data or metadata checks: ordinary columns/defaults/precision, auto-increment, stored generated columns, an unused AUTO_INCREMENT=3000000000 starting 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.
  • Kingbase PG-mode verification: Deployed the official KingbaseES_V009R001C010B0004_aarch64_Docker.tar image and confirmed KingbaseES V009R001C010, database_mode=pg. Direct invocation of the unchanged PR's KingBaseMetaData.tableDDL with 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 MySQL NAMES clause. Cleanup left zero test schemas or roles.
  • Additional verification: The final catalog queries passed PostgreSQL 17.10 checks for standalone enum references and identity metadata; the temporary schema was rolled back. Earlier PostgreSQL checks also covered dropped columns and column privileges.
  • Server capability limit: This Kingbase build rejects VIRTUAL generated-column syntax when creating a fixture; that scenario is explicitly not counted as an integration pass.
  • UI evidence: N/A - database metadata generation only.

Risk and compatibility

  • Public API or stored data: N/A - no API or application-storage changes; exported column DDL now uses the database's complete type spelling.
  • Database or driver compatibility: Real Kingbase validation used V009R003C018 in MySQL mode and V009R001C010 in PG mode, both with the configured default JDBC driver. The exact reported V009R003C011PS021 patch build remains untested.
  • Network, privacy, or security: Metadata reads retain column access checks and bound table/schema filters. Sequence identifiers are quoted and escaped; exporting does not modify the source database. The emitted SQL restores the destination auto-increment state.
  • Community / Local / Pro boundary: N/A - no edition-specific behavior changes.
  • Backward compatibility: Catalog results without attidentity or attgenerated remain supported. Identity sequence lookup is only performed for identity columns; unavailable sequence metadata raises an error instead of silently changing the definition.

Reviewer map

  • Start here: SqlConstant.COLUMN_SQL, IDENTITY_SEQUENCE_SQL and SEQUENCE_STATE_SQL, then KingBaseMetaData.tableDDL, appendIdentityOptions and appendAutoIncrement; regression coverage is in KingBaseTableDDLTest.
  • Failure condition: Table DDL export against a compatibility view without udt_name; also verify complete type/default/identity definitions on the target Kingbase version.
  • Rollback or disable path: Revert this PR. No migration or stored-data rollback is required.

Contributor declaration

  • I linked the Issue that defines this change.
  • I tested the affected behavior and reported the actual results above.
  • I did not include credentials, private data, or generated build output.
  • I disclosed substantial AI assistance below, or this PR contains no substantial AI-generated code.

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.

@openai0229
openai0229 merged commit 32cf6b2 into main Sep 7, 2026
14 of 16 checks passed
@openai0229
openai0229 deleted the fix/kingbase-ddl-catalog-metadata branch September 7, 2026 06:30
@openai0229 openai0229 moved this from In Review to Done in Chat2DB Community Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant