Repository navigation
[Fix][Connector-V2][JDBC] Report the declared length of Dameng NVARCHAR and NVARCHAR2 - #12882
Conversation
DanielLeens
left a comment
There was a problem hiding this comment.
What Problem Does This PR Solve?
- User pain point: Dameng
NVARCHAR(n)andNVARCHAR2(n)were catalogued using byte length, making a character-length column appear two or four times wider and propagating an incorrect schema to downstream auto-created tables. - Fix approach: query the declared
SYS.SYSCOLUMNS.LENGTH$and use it for national variable-width character types, with safe fallbacks toCHAR_LENGTHand then the existing byte length. - One-sentence summary: the Dameng JDBC catalog now reports national character columns in their declared character unit.
1. Code Change Review
1.1 Core Logic Analysis
Reviewed head: 8a8c4b86ee4579ab8315490af2fa05cc5a922699. The runtime path is JDBC catalog metadata lookup -> DamengCatalog.getTable() -> SELECT_COLUMNS_SQL -> buildColumn() -> nationalCharLength() -> DmdbTypeConverter. The changed boundary is correct: the unit conversion belongs where Dameng metadata becomes a SeaTunnel catalog column, not in downstream sinks.
// before
long columnLength = resultSet.getLong("DATA_LENGTH");
// after
long columnLength = nationalCharLength(typeName,
resultSet.getLong("DATA_LENGTH"), resultSet.getLong("CHAR_LENGTH"),
resultSet.getLong("DECLARED_LENGTH"));Key findings:
- The normal catalog path reaches the conversion before source schema and sink auto-create consume the column definition.
- Only
NVARCHARandNVARCHAR2change; CHAR, VARCHAR, VARCHAR2, NCHAR, and binary types keep their prior byte-length behavior. - The declared-length fallback avoids guessing a charset conversion ratio when catalog metadata is incomplete.
- This is a precise schema-correction fix and the intentional schema impact is documented in both languages.
Runtime path:
JDBC source discovers Dameng table
-> DamengCatalog executes metadata query with SYS.SYSCOLUMNS join
-> buildColumn reads declared national-character length
-> DmdbTypeConverter builds SeaTunnel Column
-> source schema and downstream auto-create use the corrected length
1.2 Compatibility Impact
Partially incompatible by design: newly discovered NVARCHAR/NVARCHAR2 column definitions can become narrower because they now reflect characters rather than bytes. Existing downstream tables are not altered. Both incompatible-change notes explain the impact and migration option.
1.3 Performance / Side-Effect Analysis
The metadata query adds catalog joins only during schema discovery. Per-row source processing, checkpointing, concurrency, retries, and resources are unchanged.
1.4 Error Handling and Logging
The fallback preserves the old byte length when declared metadata is unavailable, preferring oversizing over possible truncation. No sensitive information is logged. No source-level blocking issue was found.
2. Code Quality Assessment
2.1 Coding Standards
The national-character calculation has a detailed contract comment and the SQL join explains why CHAR_LENGTH alone is insufficient for NVARCHAR2.
2.2 Test Coverage and Test Stability
Parameterized unit coverage includes GB18030 and UTF-8, both national types, LENGTH_IN_CHAR variants, fallbacks, unaffected types, and buildColumn. The updated JdbcDmIT provides the database-level coverage. Stability rating: Stable. The added assertions use deterministic catalog data and do not add sleeps, fixed ports, or order-dependent state.
2.3 Documentation Updates
The English and Chinese incompatible-change entries accurately describe source-schema and auto-create impact.
3. Architectural Soundness
3.1 Elegance of the Solution
Precise fix at the catalog metadata boundary.
3.2 Maintainability
The helper makes the type-specific unit contract explicit and safely isolates it from unrelated types.
3.3 Extensibility
Additional Dameng metadata exceptions can be handled in the same catalog layer.
3.4 Historical-Version Compatibility
The documented schema correction is the only compatibility effect; existing sink tables remain untouched.
4. Issue Summary
| Number | Issue | Location | Severity |
|---|---|---|---|
| — | No source-level blocking issues found | — | — |
5. Merge Recommendation
Conclusion: Ready to merge after fixes
-
Blockers — must be fixed
- No source-level blocker was found. The current
Buildcheck is still in progress; wait for the JDBC/Dameng CI evidence before merge.
- No source-level blocker was found. The current
-
Recommended fixes — non-blocking
- None.
Overall assessment: the change corrects the type unit at the smallest safe and globally appropriate metadata boundary. Local analysis covered the complete diff, catalog call chain, converter behavior, unit matrix, E2E additions, and documentation; git diff --check passed. No local compilation or execution was performed under the SeaTunnel review policy.
|
The red That option came in with #12792, which is in this branch's base ( Once #12875 is merged I'll rebase and post the new result. |
|
Thanks for digging into the red Please sync the latest |
|
@SEZ9 Thanks. All three are covered in #12882:
CI is still red only because of #12874 (fix in #12875); I'll sync dev and rerun the failed jobs once #12875 is merged. |
|
Thanks for mapping those cases to the catalog tests and the read-only-user E2E, @zhengxiang378928908-code. There is no new code in this exchange, so my earlier source-level conclusion remains unchanged; this reply does not claim a fresh run or full rereview. @SEZ9 can use those pointers for the independent recheck. The upstream CI dependency has not changed: #12875 is still open, so the fix for #12874 is not in current |
8a8c4b8 to
517d260
Compare
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks for rebasing, @zhengxiang378928908-code. Since my last review at 8a8c4b8, the head is now 517d260 (a single commit rebased onto current dev). I compared the PR-only diff of both heads line by line and it is identical: the same five files (DamengCatalog, DamengCatalogTest, JdbcDmIT, and the English/Chinese incompatible-changes pages). The rebase also picks up the upstream fix for the JDBC option completeness failure (#12938 is in dev, and #12875 was closed as superseded), so the earlier unrelated red Build should no longer apply. This is a full fresh review of the current head. My earlier conclusion on the code is unchanged, and none of my previous findings were open (I had no numbered issues).
What Problem Does This PR Solve?
- User pain point: Dameng
NVARCHAR(n)andNVARCHAR2(n)hold n characters, but the catalog readALL_TAB_COLUMNS.DATA_LENGTH(bytes), soNVARCHAR(10)was reported asNVARCHAR(20)on GB18030 orNVARCHAR(40)on UTF-8, and downstream auto-created tables were two to four times too wide. - Fix approach: join
SYS.SYSCOLUMNSto read the declaredLENGTH$, use it forNVARCHAR/NVARCHAR2, and fall back toCHAR_LENGTH, then to the old byte length. - One-sentence summary: the Dameng JDBC catalog now reports national variable-width character columns in their declared character unit.
Example:
Before: NVARCHAR(10) on a GB18030 database -> source type NVARCHAR(20) -> MySQL sink VARCHAR(80)
After: NVARCHAR(10) on a GB18030 database -> source type NVARCHAR(10) -> MySQL sink VARCHAR(40)
1. Code Change Review
1.1 Core Logic Analysis
Reviewed head: 517d260a3508932003e88d3a812b9b0891467a21. Changed files: DamengCatalog.java (SQL + buildColumn + new nationalCharLength), DamengCatalogTest.java (new), JdbcDmIT.java, and docs/{en,zh}/introduction/concepts/incompatible-changes.md.
// before
long columnLength = resultSet.getLong("DATA_LENGTH");
// after
long columnLength = nationalCharLength(typeName,
resultSet.getLong("DATA_LENGTH"), resultSet.getLong("CHAR_LENGTH"),
resultSet.getLong("DECLARED_LENGTH"));Runtime flow:
JDBC source/sink resolves a Dameng table
-> DamengCatalog.getTable() runs SELECT_COLUMNS_SQL
(ALL_TAB_COLUMNS LEFT JOIN comments LEFT JOIN SYSOBJECTS(SCH) / SYSOBJECTS(TAB) / SYSCOLUMNS)
-> buildColumn() -> nationalCharLength(): NVARCHAR/NVARCHAR2 -> LENGTH$ > CHAR_LENGTH > DATA_LENGTH
-> DmdbTypeConverter.convert() builds the SeaTunnel Column
-> source schema and sink auto-create use the corrected length
Findings:
- The normal user path (any Dameng table discovered through
DamengCatalog) reaches the changed logic. Per-row read/write paths, splits, checkpoints and serialization are untouched. - All joins are LEFT JOINs, so a missing or unreadable system-table row yields
DECLARED_LENGTH = 0viagetLong, and the code falls back instead of dropping the column or failing. A user with onlySELECTon the table is covered by the E2E. - Only
NVARCHAR/NVARCHAR2(case-insensitive) change;CHAR,VARCHAR,VARCHAR2,NCHARand binary types keepDATA_LENGTH, which is the pre-change behavior. - The
SELECT_COLUMNS_SQLchange keeps its existing%splaceholders and column order, and the previously selected columns are unchanged.
1.2 Compatibility Impact
Partially incompatible (by design, documented). Newly discovered NVARCHAR/NVARCHAR2 source types and sink auto-create lengths become narrower, but still hold every source value because the length is counted in characters. No option names, defaults, public APIs or serialization formats change, and existing downstream tables are not altered. Both the English and Chinese incompatible-change entries describe the impact and migration path.
1.3 Performance / Side-Effect Analysis
The extra joins run once per table at schema discovery, keyed by object id and name, so there is no per-row or per-checkpoint cost, and no new threads, connections or resources. At the production scale of very large data volumes this is not on the data path.
1.4 Error Handling and Logging
The fallback chain preserves the previous byte length when metadata is unavailable (oversizing, never truncating). No new exceptions are introduced and nothing sensitive is logged. No source-level issue was found, so there are no formal issues to list (Issue count: 0).
2. Code Quality Assessment
2.1 Coding Standards
The new nationalCharLength has a complete Javadoc with parameters and the reason DATA_LENGTH and CHAR_LENGTH are insufficient, and the SQL join carries an explanatory comment. The new test class has the ASF header. No missing-comment issue.
2.2 Test Coverage and Test Stability
DamengCatalogTest is a parameterized matrix over NVARCHAR/NVARCHAR2, GB18030/UTF-8, LENGTH_IN_CHAR 0/1, fallbacks, unaffected types, and buildColumn with a mocked ResultSet. It is deterministic. JdbcDmIT#testNationalCharLengthFromCatalog checks real catalog output on the default database and on a second container initialized with LENGTH_IN_CHAR=1 CHARSET=1, plus a read-only user. The second container uses a mapped (non-fixed) port and a readiness log wait with a 5-minute timeout, and it cleans up the table and user in finally. Stability rating: Stable. Only the extra container start-up time is worth keeping an eye on in CI.
2.3 Documentation Updates
docs/en and docs/zh incompatible-changes entries are present, consistent with each other, and match the code (source column and the 1/2 or 1/4 factor for auto-create).
3. Architectural Soundness
3.1 Elegance of the Solution
Precise fix at the catalog metadata boundary, with the logic isolated in connector code (no engine/core/API change).
3.2 Maintainability
A small static helper with an explicit per-type contract; easy to extend if another Dameng type needs the same treatment.
3.3 Extensibility
Further Dameng metadata exceptions can be added in the same helper and query without touching shared classes.
3.4 Historical-Version Compatibility
Job configs and options are unchanged. The only effect is the documented schema correction for newly resolved columns.
4. Issue Summary
| Number | Issue | Location | Severity |
|---|---|---|---|
| - | No source-level issues found | - | - |
5. Merge Recommendation
Conclusion: Ready to merge after fixes
-
Blockers - must be fixed
- No source-level blocker. The only gate is a green
Buildon this head (see below).
- No source-level blocker. The only gate is a green
-
Recommended fixes - non-blocking
- None.
CI / merge state: for head 517d260, the contributor fork's Build run (https://github.com/zhengxiang378928908-code/seatunnel/actions/runs/39915800508) was in_progress when I checked, and the apache-side PR signal run completed with action_required (that is only the pointer check that waits on the fork run). The previous red was JdbcOptionRuleCompletenessTest from the numeric_special_value_as_null option, which dev has since fixed via #12938; this head is rebased on that dev. The merge state shows BLOCKED pending required checks/approvals, and the branch is mergeable with no conflicts. Being behind dev is only metadata. No local build or test was run (analysis is by code reading); please let the fork Build finish and, if any job fails, tell me which lane so I can check whether it relates to this diff.
Overall assessment: this is a small, well-bounded and well-tested correction of a real unit mismatch, with the compatibility effect documented. I see nothing to change in the code. @SEZ9, your earlier three questions are answered in the author's reply (NVARCHAR2 with CHAR_LENGTH = 0, read-only user, unaffected CHAR/VARCHAR/NCHAR) and I verified those cases in the tests above.
Alternatives: keeping the byte length and dividing by a charset ratio would be a guess and was rightly avoided.
|
Thanks, @DanielLeens. The fork |
|
Thanks for the update, @zhengxiang378928908-code, and for linking the run. I checked fork run 39915800508: it is There is no new code since my last review, so my source-level conclusion is unchanged: no source-level blocker. I did not rerun anything locally. I also did not separately confirm which lane executed Nothing further is needed from you. The PR is still waiting on the required review approval, which is not something you need to act on, and @SEZ9 can finish the independent recheck. Thanks again for the clear validation write-up. |
…AR and NVARCHAR2 Fixes apache#12752. DamengCatalog took the length of every column from ALL_TAB_COLUMNS.DATA_LENGTH. For NVARCHAR(n) and NVARCHAR2(n) that is a byte count, n * 2 on GB18030 and n * 4 on UTF-8, while the columns hold n characters. NVARCHAR(10) was reported as NVARCHAR(20) or NVARCHAR(40). The view definition shows DATA_LENGTH = SYSCOLUMNS.LENGTH$ * 2 or * 4 for character-length columns, and CHAR_LENGTH = LENGTH$ only for a type list that leaves out NVARCHAR2. The catalog now also selects SYS.SYSCOLUMNS.LENGTH$ and uses it for NVARCHAR and NVARCHAR2, then CHAR_LENGTH, then DATA_LENGTH (the old behavior, which oversizes but never truncates). All other types keep DATA_LENGTH. Measured on DM V8 with LENGTH_IN_CHAR 0/1 and GB18030/UTF-8: in all four, NVARCHAR(n) and NVARCHAR2(n) take exactly n characters, and LENGTH$ is n. A user that can only read the table can read LENGTH$. - DamengCatalogTest: the measured matrix, fallbacks, unchanged CHAR/VARCHAR/NCHAR, and buildColumn. - JdbcDmIT: the image's default database (LENGTH_IN_CHAR=0, GB18030), a second one initialized with LENGTH_IN_CHAR=1 and UTF-8, and a read-only user. - incompatible-changes (en/zh). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
517d260 to
02c5b80
Compare
DanielLeens
left a comment
There was a problem hiding this comment.
Thanks for rebasing again, @zhengxiang378928908-code. The head is now 02c5b80ddf4f9eb72f2d2a700e9d9813cf63da0e, one commit on top of the current dev tip (9ab97e15f). I compared it with the previous head 517d260 using git range-diff. The production code, the tests and the wording of both incompatible-changes.md entries are unchanged. The only difference is where the entries sit in the ## dev section, which moved because of new upstream entries. That is the expected result of the rebase. This is a fresh full review of the current head. My earlier conclusion on the code still holds, and I had no open numbered issues.
What Problem Does This PR Solve?
- User pain point: Dameng
NVARCHAR(n)/NVARCHAR2(n)hold n characters, butDamengCatalogreadALL_TAB_COLUMNS.DATA_LENGTH, which is a byte count (2n on GB18030, 4n on UTF-8). SoNVARCHAR(10)was reported asNVARCHAR(20)orNVARCHAR(40), and sink auto-create made columns two to four times too wide. - Fix approach: also select
CHAR_LENGTHandSYS.SYSCOLUMNS.LENGTH$(the declared length, through LEFT JOINs onSYS.SYSOBJECTS). ForNVARCHAR/NVARCHAR2only, useLENGTH$, thenCHAR_LENGTH, then the oldDATA_LENGTH. - One-sentence summary: the Dameng catalog now reports national variable-width character columns in their declared character unit.
1. Code Change Review
1.1 Core Logic Analysis
Changed files: DamengCatalog.java (SELECT_COLUMNS_SQL, buildColumn, new nationalCharLength), new DamengCatalogTest.java, JdbcDmIT.java, and docs/{en,zh}/introduction/concepts/incompatible-changes.md.
// before (DamengCatalog.buildColumn)
long columnLength = resultSet.getLong("DATA_LENGTH");
// after
long columnLength = nationalCharLength(typeName,
resultSet.getLong("DATA_LENGTH"), resultSet.getLong("CHAR_LENGTH"),
resultSet.getLong("DECLARED_LENGTH"));Runtime flow:
JDBC source (table_path) / sink (save mode, auto-create) resolves a Dameng table
-> DamengCatalog.getTable(TablePath) -> SELECT_COLUMNS_SQL
ALL_TAB_COLUMNS LEFT JOIN ALL_COL_COMMENTS
LEFT JOIN SYSOBJECTS SCH (TYPE$='SCH') -> SYSOBJECTS TAB (TYPE$='SCHOBJ') -> SYSCOLUMNS
-> buildColumn() -> nationalCharLength(): NVARCHAR/NVARCHAR2 -> LENGTH$ > CHAR_LENGTH > DATA_LENGTH
-> DmdbTypeConverter.convert(): sourceType "<type>(n)", columnLength = charTo4ByteLength(n)
-> source CatalogTable schema and downstream sink auto-create
Key findings:
- The normal user path (any Dameng table resolved through
DamengCatalog.getTable(TablePath)) reaches the change. Row reading and writing, splits, checkpoints and serialization are untouched. - Every new join is a LEFT JOIN, and
getLongreturns 0 for SQL NULL. So when the system-table lookup misses or cannot be read, the column falls back to the previous length. Nothing is dropped and nothing fails. The join keys (schema object by name andTYPE$='SCH', schema object bySCHID, name andTYPE$='SCHOBJ', column by object id and name) identify one row per column. I do not see a way for them to duplicate rows. - Only
NVARCHAR/NVARCHAR2(case-insensitive) change.CHAR,VARCHAR,VARCHAR2,NCHAR, binary and LOB types keepDATA_LENGTH, exactly as before. The existing%splaceholders, the column order and theSOURCE_TYPEexpression are unchanged. - The query-mode path (
getTable(String sqlQuery), which uses JDBCResultSetMetaData) is not touched, so this PR does not change it.
1.2 Compatibility Impact
Partially incompatible (by design, documented). For newly discovered NVARCHAR / NVARCHAR2 columns, the source type and the auto-create length become narrower. They still hold every source value, because the length is now counted in characters. No option, default, public API or serialization format changes, and existing downstream tables are not altered. Both the EN and ZH incompatible-changes.md entries describe the impact and the migration path, and they are consistent with each other and with the code.
1.3 Performance / Side-Effect Analysis
The extra joins run once per table at schema discovery and use object id / name keys. There is no per-row or per-checkpoint cost, and no new threads, connections or resources. Even at very large data volumes this is not on the data path.
1.4 Error Handling and Logging
The fallback chain keeps the previous byte length when the metadata is unavailable, so it may oversize but never truncates. No new exceptions are introduced and nothing sensitive is logged. Formal issues: none.
2. Code Quality Assessment
2.1 Coding Standards
nationalCharLength has a complete Javadoc, which explains why neither DATA_LENGTH nor CHAR_LENGTH is sufficient. The new join has a why-comment, and the new test class has the ASF header. A tiny style point, not an issue: INIT_LENGTH_IN_CHAR_UTF8 in JdbcDmIT is a static final field declared between methods. Moving it next to the other constants would read a little better.
2.2 Test Coverage and Test Stability
DamengCatalogTestis a deterministic, parameterized matrix: both national types, GB18030 / UTF-8,LENGTH_IN_CHAR0 / 1,CHAR_LENGTH = 0forNVARCHAR2, the missing-LENGTH$and missing-CHAR_LENGTHfallbacks, unaffected types, andbuildColumnwith a mockedResultSet. RevertingbuildColumntoDATA_LENGTH, or dropping theLENGTH$priority, turns it red.JdbcDmIT#testNationalCharLengthFromCatalogchecks real catalog output, and the expected values would fail on the old code (NVARCHAR(20)/ 80 instead ofNVARCHAR(10)/ 40). It runs on the default database (GB18030,LENGTH_IN_CHAR=0), on a second container initialized withLENGTH_IN_CHAR=1 CHARSET=1, and as a read-only user. It also asserts the database mode first, so a changed image default cannot make the test pass silently. The second container uses a mapped port, waits for a readiness log line with a 5-minute timeout, and is closed by try-with-resources. Table and user are cleaned up infinally.- Stability rating: Stable. The only cost is the extra container start-up time in the JDBC part-5 lane.
2.3 Documentation Updates
The EN and ZH incompatible-change entries are present, rebased cleanly into the current ## dev section, and match the code. No connector option or user page needs an update.
3. Architectural Soundness
- 3.1 Elegance: Precise fix at the catalog metadata boundary, inside connector code (no engine, core or API change). It avoids the tempting but wrong "divide
DATA_LENGTHby a charset ratio". - 3.2 Maintainability: a small static helper with an explicit per-type contract.
- 3.3 Extensibility: other Dameng metadata exceptions (for example
VARCHAR(n CHAR), which the PR description deliberately leaves for a separate issue) can be handled in the same layer. - 3.4 Historical-Version Compatibility: job configs and options are unchanged. The only effect is the documented schema correction for newly resolved columns.
4. Issue Summary
| Number | Issue | Location | Severity |
|---|---|---|---|
| - | No issues found | - | - |
5. Merge Recommendation
CI: the rebase restarted CI. The fork Build for this head (run 40086136661) is queued, and the apache-side Build check has not reported yet. The previous head 517d260 was fully green (run 39915800508), and the PR-only diff is the same, so I expect the same result, but it still has to finish. The branch is level with dev (ahead 1, behind 0), with no conflicts.
Conclusion: Ready to merge
- Blockers (must fix): none. No blocking issues found.
- Recommended fixes (non-blocking): none (the
JdbcDmITconstant placement is optional).
Overall assessment: a small, well-bounded and well-tested correction of a real unit mismatch, with the compatibility effect documented. The remaining gates are a green Build on this head and a write-capable committer approval. Residual risk: Dameng versions other than the DM8 image used in CI. The LEFT JOIN fallback keeps the old byte length there, so the worst case is the previous oversizing, never truncation. Nothing was built or executed locally. This review is based on the full diff, the call chain at this head, and the previous green CI evidence.
Better alternative: none. Dividing DATA_LENGTH by a charset ratio would be a guess, and the PR rightly avoids it.
|
@DanielLeens The fork The first attempt failed in |
|
Thanks for rerunning only the affected job, @zhengxiang378928908-code. I checked Build 40086136661: it is completed/success on the current |
|
Thanks for the update, @zhengxiang378928908-code. I checked fork run 40086136661: attempt 2 is completed/success and bound to the unchanged head 02c5b80. The first-attempt failure in mysql-cdc-connector-it (11) was a Maven wrapper startup error before any test ran, so rerunning only that job is the right call and it is unrelated to this change. My review found no blockers, and the CI gate is now met, so my conclusion on this head is ready to merge. The remaining gate is an approval from a committer with write access. Nothing was executed locally; this is based on code reading and the fork CI evidence. |
Purpose of this pull request
Fixes #12752.
DamengCatalogtook every column's length fromALL_TAB_COLUMNS.DATA_LENGTH. ForNVARCHAR(n)andNVARCHAR2(n)that is a byte count, while the columns hold n characters, soNVARCHAR(10)was reported asNVARCHAR(20)(GB18030) orNVARCHAR(40)(UTF-8), and the length was then expanded again for SeaTunnel's column length.Following @DanielLeens's review in #12752, this PR selects the metadata explicitly and does not divide
DATA_LENGTH.What Dameng actually stores. The definition of
SYS.ALL_TAB_COLUMNS(fromSYS.SYSTEXTS) is:SYS.SYSCOLUMNS.LENGTH$is the declared length.DATA_LENGTHmultiplies it by the charset's bytes per character for character-length columns (SCALE = 7), andCHAR_LENGTHis 0 forNVARCHAR2only because the view leaves it out of the list. SoDATA_LENGTH / 2would be wrong on a UTF-8 database.Change.
SELECT_COLUMNS_SQLalso selectsALL_TAB_COLUMNS.CHAR_LENGTHandSYS.SYSCOLUMNS.LENGTH$(LEFT JOIN throughSYS.SYSOBJECTSon owner, table and column name). ForNVARCHARandNVARCHAR2only, the length isLENGTH$, thenCHAR_LENGTHifLENGTH$is missing, thenDATA_LENGTH(the current behavior, which oversizes but never truncates). All other types keepDATA_LENGTH, soCHAR,CHARACTER,VARCHAR,VARCHAR2andNCHARare unchanged.Measurements on DM V8 (
0x7000c, thelaglangyue/dmdb8image used byJdbcDmIT), with four databases initialized bydminitwith eachLENGTH_IN_CHAR/CHARSETcombination:NVARCHAR(10)DATA_LENGTH / CHAR_LENGTH / LENGTH$NVARCHAR2(10)DATA_LENGTH / CHAR_LENGTH / LENGTH$NVARCHAR(100),NVARCHAR2(100)NVARCHAR(10)andNVARCHAR2(10)aok, 11 ×arejected, 10 ×达okCHAR(10),VARCHAR(10),VARCHAR2(10),NCHAR(10)So in every mode
NVARCHAR(n)andNVARCHAR2(n)hold exactly n characters, andLENGTH$is n.LENGTH_IN_CHARdoes not change their metadata. A user that only hasSELECTon the table (defaultPUBLICrole) can readSYS.SYSCOLUMNSand gets the same values.Not changed here:
VARCHAR(n CHAR)has the same pattern (DATA_LENGTH2n/4n,LENGTH$n). It keeps the currentVARCHAR2(DATA_LENGTH)mapping, because changing it toVARCHAR2(n)would make a Dameng sink table byte-length and too small for multi-byte values. Fixing it properly means keeping theCHARlength semantics in the source type, so I'd suggest a separate issue if you think it is worth it.Does this PR introduce any user-facing change?
Yes. For Dameng
NVARCHAR(n)/NVARCHAR2(n), the source type changes fromNVARCHAR(2n)/NVARCHAR(4n)toNVARCHAR(n), and the column length used for sink auto-create is halved (GB18030) or quartered (UTF-8). For example,NVARCHAR(10)getsVARCHAR(40)instead ofVARCHAR(80)on a MySQL sink. The new columns still hold every source value, since the length is counted in characters. Existing tables are not altered. Recorded inincompatible-changes.md(en/zh).How was this patch tested?
DamengCatalogTest(new): the measured matrix above forNVARCHAR/NVARCHAR2(includingCHAR_LENGTH = 0), the fallbacks whenLENGTH$orCHAR_LENGTHis missing, unchangedCHAR/CHARACTER/VARCHAR/VARCHAR2/NCHAR/VARCHAR(10 CHAR), andbuildColumnend to end with a mockedResultSet(source type and column length).JdbcDmIT#testNationalCharLengthFromCatalog(new): runsDamengCatalog#getTableagainst real Dameng:LENGTH_IN_CHAR=0, GB18030), asSYSDBAand as a user with onlySELECTon the table;LENGTH_IN_CHAR=1andCHARSET=1(UTF-8);ais rejected), and the source type and length ofNVARCHAR(10/100),NVARCHAR2(10/100),NCHAR,CHAR,VARCHAR,VARCHAR2.DamengCatalogTest,DmdbTypeConverterTestandDamengCreateTableSqlBuilderTestpass (73 tests), andJdbcDmIT#testNationalCharLengthFromCatalogpasses.Check list
incompatible-changes.mdupdated (en/zh).🤖 Generated with Claude Code