zhengxiang378928908-code opened a new issue, #12752: URL: https://github.com/apache/seatunnel/issues/12752
### Search before asking - [X] I had searched in the [issues](https://github.com/apache/seatunnel/issues?q=is%3Aissue+label%3A%22bug%22) and found no similar issues. ### What happened For Dameng `NVARCHAR(n)` and `NVARCHAR2(n)` columns, the JDBC catalog reports twice the declared length. For example, `NVARCHAR(10)` comes back from `DamengCatalog#getTable` with `sourceType = NVARCHAR(20)` and `columnLength = 80`. The cause is that `DamengCatalog#SELECT_COLUMNS_SQL` reads `ALL_TAB_COLUMNS.DATA_LENGTH`, which is a byte count for these two types. Their capacity, however, is in characters. I verified this on a real instance (`laglangyue/dmdb8`, the image used by `JdbcDmIT`; DM V8, `LENGTH_IN_CHAR=0`): | Declared | `DATA_LENGTH` | `CHAR_LENGTH` | 10 × `a` | 11 × `a` | 10 × `达` | SeaTunnel on `dev` | |---|---|---|---|---|---|---| | `NVARCHAR(10)` | **20** | 10 | ok | rejected | ok | `NVARCHAR(20)`, length 80 | | `NVARCHAR2(10)` | **20** | 0 | ok | rejected | ok | (same `DATA_LENGTH` path) | | `NCHAR(10)` | 10 | 10 | ok | rejected | rejected | `NCHAR(10)`, length 40 | | `VARCHAR(10)` | 10 | 10 | ok | rejected | rejected | `VARCHAR2(10)`, length 40 | So `NVARCHAR(10)` holds exactly 10 characters, multi-byte or not, while Dameng reports `DATA_LENGTH = 20`. `NCHAR` and `VARCHAR` don't have this mismatch, since their `DATA_LENGTH` equals the declared length. Impact: the column's source type is reported as `NVARCHAR(20)` rather than the declared `NVARCHAR(10)`, and the length used for sink auto-create is doubled. This oversizes target columns but loses no data, so it is a metadata-correctness issue rather than a failure. This also confirms the `LENGTH_IN_CHAR` concern raised in the review of #11684. That PR maps `NVARCHAR2` through the existing `NVARCHAR` branch, so it inherits this behaviour rather than introducing it. A possible fix is to take the length from `CHAR_LENGTH` for `NVARCHAR`. `CHAR_LENGTH` is 0 for `NVARCHAR2` on this version, so `NVARCHAR2` would need a different source, for example `DATA_LENGTH / 2`. I'd like a maintainer's view on the preferred approach, and on whether `LENGTH_IN_CHAR=1` instances should be covered too, before opening a PR. ### SeaTunnel Version dev (b0f6feddf) ### SeaTunnel Config ```sql -- Dameng CREATE TABLE SYSDBA.T_NVC (ID INT, V NVARCHAR(10)); SELECT DATA_TYPE, DATA_LENGTH, CHAR_LENGTH FROM ALL_TAB_COLUMNS WHERE OWNER = 'SYSDBA' AND TABLE_NAME = 'T_NVC' AND COLUMN_NAME = 'V'; -- NVARCHAR | 20 | 10 ``` ### Running Command ```shell # DamengCatalog#getTable(TablePath.of("DAMENG", "SYSDBA", "T_NVC")) against the instance above ``` ### Error Exception ```log No exception. Column V is reported as sourceType=NVARCHAR(20), columnLength=80 (declared NVARCHAR(10)). ``` ### Zeta or Flink or Spark Version Zeta ### Java or Scala Version Java 8 ### Screenshots _No response_ ### Are you willing to submit PR? - [X] Yes I am willing to submit a PR! ### Code of Conduct - [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- 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]
