Skip to content

[Bug] [Connector-V2] [JDBC] MySQL DECIMAL with precision > 38 is clamped to DECIMAL(38, 18), losing digits in non-MySQL sinks #12841

Open

Description

Search before asking

  • I searched in the issues and found nothing similar.

What happened

Split out of #12814, where the Spark wide-decimal policy is discussed. That issue explicitly keeps this source-side clamp out of scope because it happens on every engine, not only Spark.

MySqlTypeConverter.convert maps any signed DECIMAL(p, s) with p > 38 to DECIMAL(38, 18), whatever the original scale:

case MYSQL_DECIMAL:
    ...
    if (typeDefine.getPrecision() > DEFAULT_PRECISION) {   // 38
        log.warn("{} will probably cause value overflow.", MYSQL_DECIMAL);
        decimalType = new DecimalType(DEFAULT_PRECISION, DEFAULT_SCALE); // (38, 18)
    }

From reading the current dev code (51f553cb4), this causes the following. Reproduced end to end on e2957d27a (Zeta local, MySQL 8.0 → PostgreSQL 16 and MySQL 8.0 → MySQL 8.0); see this comment for details. Item 4 turned out to be wrong and is corrected below.

  1. Integer digits are cut to 20. DECIMAL(65, 0) becomes DECIMAL(38, 18), which has room for only 20 integer digits. A value with 30 integer digits stored in a DECIMAL(65, 0) column no longer fits, even though the column needs no scale at all. (Corrected: a column declared DECIMAL(30, 0) is not affected, because the clamp only applies when p > 38.)
  2. Fraction digits above 18 are cut. DECIMAL(50, 30) becomes scale 18.
  3. The declared type no longer matches the values. The JDBC row converter reads the value with getBigDecimal and does not rescale it (AbstractJdbcRowConverter, case DECIMAL), so a row can carry e.g. a 26-digit integer while the column type says DECIMAL(38, 18). The mismatch shows up later in the sink, far from its cause.
  4. It even breaks MySQL -> MySQL. Corrected: MySQL -> MySQL is not affected. When both sides are MySQL, MysqlCreateTableSqlBuilder reuses the column's source type (decimal(65,0), decimal(50,30)) instead of the converted type, and the reader passes the BigDecimal through unchanged, so the auto-created table and the values round-trip. The clamp hits sinks that build their DDL from the SeaTunnel type, e.g. MySQL -> PostgreSQL gets NUMERIC(38, 18): rows with more than 20 integer digits fail with numeric field overflow, and fraction digits beyond 18 are rounded silently (0.000000000000000000000000000001 is stored as 0, job reports success).
  5. Signed and unsigned behave differently. DECIMAL UNSIGNED is not clamped: DECIMAL(p, s) UNSIGNED becomes DECIMAL(p + 1, s), so DECIMAL(65, 0) UNSIGNED becomes DECIMAL(66, 0) while the signed DECIMAL(65, 0) becomes DECIMAL(38, 18).
  6. The only signal is a WARN. The log line has no column name or target type in it, and GenericTypeConverter does the same clamp without any log at all.

The same p > 38 -> (38, 18) clamp exists in:

  • MySqlTypeConverter (also used by MySQL-CDC through MySqlTypeUtils)
  • OceanBaseMySqlTypeConverter
  • GenericTypeConverter

(Other converters such as Oracle, Dameng, Xugu and YashanDB use (38, 18) only for an unknown precision, or their database maximum is 38 anyway, so they are not affected.)

For comparison, PostgresTypeConverter keeps the declared precision (NUMERIC(50, 0) -> DECIMAL(50, 0)), and sinks with a lower limit already handle wide decimals in their own reconvert (e.g. Oracle / SQL Server clamp to their maximum with a WARN that names the column).

Possible directions (for discussion)

  • A. Keep the declared type. Map DECIMAL(p, s) to DECIMAL(p, s) as PostgreSQL already does, and leave narrowing to each sink's reconvert. Spark is covered separately by [Discussion][Translation][Spark] Explicit policy for DECIMAL precision > 38 on the Spark engine #12814. This changes the schema seen by sinks for p > 38, so it needs an incompatible-changes.md entry.
  • B. Keep a 38 cap, but keep integer digits first. E.g. DECIMAL(38, max(0, 38 - (p - s))), plus a WARN with the column name, the original type and the new type. Still lossy, but DECIMAL(65, 0) would at least become DECIMAL(38, 0) instead of DECIMAL(38, 18).
  • Either way: make signed and unsigned consistent, apply the same rule to the OceanBase and generic converters, and add a WARN to the generic converter.

I'd prefer A, because a value that the source can hold and the sink can hold should not be lost in between. I'd like a maintainer's view before writing code.

SeaTunnel Version

dev (51f553cb4)

SeaTunnel Config

env {
  parallelism = 1
  job.mode = "BATCH"
}

source {
  Jdbc {
    url = "jdbc:mysql://mysql:3306/test"
    driver = "com.mysql.cj.jdbc.Driver"
    user = "root"
    password = "***"
    table_path = "test.t_wide_decimal"   # id INT, amount DECIMAL(65, 0), ratio DECIMAL(50, 30)
  }
}

sink {
  Jdbc {
    url = "jdbc:mysql://mysql:3306/test"
    driver = "com.mysql.cj.jdbc.Driver"
    user = "root"
    password = "***"
    database = "test"
    table = "t_wide_decimal_copy"
    generate_sink_sql = true
    schema_save_mode = "CREATE_SCHEMA_WHEN_NOT_EXIST"
  }
}

With a row such as amount = 12345678901234567890123456 (26 digits), the auto-created t_wide_decimal_copy.amount is expected to be DECIMAL(38, 18) and the write is expected to fail with Out of range value (strict mode). Corrected: this MySQL -> MySQL config works, because the MySQL sink reuses the source column type. Use a non-MySQL sink (e.g. PostgreSQL) to see the problem; the reproduction is in the comments.

Running Command

./bin/seatunnel.sh --config mysql_wide_decimal.conf -m local

Error Exception

Reproduced with a PostgreSQL sink (MySQL -> MySQL does not fail, see item 4):
WARN  MySqlTypeConverter - DECIMAL will probably cause value overflow.
...
org.postgresql.util.PSQLException: ERROR: numeric field overflow
  Detail: A field with precision 38, scale 18 must round to an absolute value less than 10^20.

Zeta or Flink or Spark Version

All engines (the clamp is in the source type converter). Spark has an additional limit tracked in #12814.

Java or Scala Version

Java 8 / 11

Screenshots

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. DanielLeens commented on Oct 17, 2026

    @DanielLeens
    Contributor

    Thank you for separating this from the Spark-specific work in #12814. The current dev paths do clamp signed MySQL DECIMAL values above 38 to DECIMAL(38, 18), while the unsigned path retains a different precision rule; that is a real JDBC schema-mapping defect and can lose integer as well as fractional capacity.

    Please open a focused PR rather than applying the same change broadly without evidence. At minimum, cover MySQL DECIMAL(65,0) and DECIMAL(50,30) through source schema discovery and MySQL sink DDL/value flow; state the intended rule for unsigned values; and treat OceanBase and GenericTypeConverter as separate, reproduced contracts unless their tests establish the same behavior. Link the Spark representation boundary to #12814, and document any observable schema-compatibility change. Classification: A — JDBC / MySQL DECIMAL schema mapping.

  2. Eymenonar commented on Oct 17, 2026

    @Eymenonar

    I will take this with a focused MySQL-only fix. I plan to preserve the declared precision and scale for signed DECIMAL values up to MySQL’s limits, define the unsigned rule explicitly, and cover source conversion plus generated MySQL DDL for DECIMAL(65,0) and DECIMAL(50,30). I will keep OceanBase and GenericTypeConverter out of scope unless their existing contracts show the same behavior.

  3. SEZ9 commented on Oct 18, 2026

    @SEZ9
    Collaborator

    Thanks for the detailed write-up, and for splitting this out of #12814.

    One correction on the report: the quoted clamp only triggers when p > 38, so a column declared DECIMAL(30, 0) is never remapped. Did you mean a value with 30 integer digits stored in a DECIMAL(65, 0) column, which would indeed not fit the 20 integer digits of DECIMAL(38, 18)? Could you confirm?

    Since the behavior so far comes from reading the code, an end-to-end reproduction of the MySQL -> MySQL case from your config (DECIMAL(65, 0), DECIMAL(50, 30), auto-created sink table) would be very helpful, ideally as an e2e test in the PR. The signed/unsigned asymmetry you describe (DECIMAL(p, s) UNSIGNED -> DECIMAL(p + 1, s) without any clamp) should be made consistent in the same change.

    On direction A vs. B: whichever is chosen, please spell out the trade-off in the PR. Note that B does not help every case: for DECIMAL(50, 30), max(0, 38 - (p - s)) still gives scale 18, i.e. the same DECIMAL(38, 18) as today. If the declared type is kept (A), an incompatible-changes.md entry is needed as you noted.

    If more than one person plans to work on this, please coordinate here first so the effort is not duplicated.

  4. zhengxiang378928908-code commented on Oct 18, 2026

    @zhengxiang378928908-code
    ContributorAuthor

    Thanks @SEZ9, you're right. DECIMAL(30, 0) is never remapped; I meant a value with 30 integer digits stored in a DECIMAL(65, 0) column, which doesn't fit the 20 integer digits of DECIMAL(38, 18). I've corrected the description. Also agreed that B doesn't help DECIMAL(50, 30), which is one more reason I lean towards A.

    On coordination: @Eymenonar has offered to take the MySQL-only fix, so I'll leave the PR to them and help with review and the end-to-end reproduction if useful.

  5. SEZ9 commented on Oct 19, 2026

    @SEZ9
    Collaborator

    @zhengxiang378928908-code thanks for the correction — that framing is right: a DECIMAL(65, 0) column holding 30 integer digits cannot survive the remap to DECIMAL(38, 18), which only leaves 20 integer digits, and DECIMAL(50, 30) loses fractional capacity for the same reason. Agreed that approach A (preserving the declared precision/scale for signed DECIMAL up to MySQL's limits) is the one to pursue, and agreed that B does not address the DECIMAL(50, 30) case.

    Coordination sounds good: @Eymenonar takes the MySQL-only fix, and your help with review plus the end-to-end reproduction would be very useful — in particular a MySQL -> MySQL run with auto-created sink tables for both DECIMAL(65, 0) and DECIMAL(50, 30) so we can confirm the DDL and values round-trip.

    @Eymenonar, for the PR please make sure it:

    • preserves declared precision and scale for signed DECIMAL above 38 instead of clamping to DECIMAL(38, 18);
    • states the intended rule for unsigned DECIMAL explicitly so signed and unsigned paths are consistent;
    • covers source schema conversion and generated MySQL sink DDL for DECIMAL(65, 0) and DECIMAL(50, 30) with tests;
    • keeps OceanBase and GenericTypeConverter out of scope unless their tests show the same clamping;
    • documents the observable schema-compatibility change for users relying on the current DECIMAL(38, 18) output.

    Please link the PR here once it is up so we can track it against this issue.

  6. zhengxiang378928908-code commented on Oct 19, 2026

    @zhengxiang378928908-code
    ContributorAuthor

    @SEZ9 I ran the end-to-end reproduction. One correction first: MySQL -> MySQL is not affected. My item 4 was wrong, and I've fixed the title and the description.

    Setup: Zeta local mode, dev at e2957d27a (starter + connector-jdbc built from it), MySQL 8.0.46 (strict mode), PostgreSQL 16. Auto-created sink tables (RECREATE_SCHEMA). Source table:

    CREATE TABLE src.wide_dec (
      id INT PRIMARY KEY,
      d65_0 DECIMAL(65,0), d50_30 DECIMAL(50,30),
      d65_0_u DECIMAL(65,0) UNSIGNED, d38_10 DECIMAL(38,10)
    );

    Six rows: 30 integer digits, the 65-digit max/min, 0 / 0.000000000000000000000000000001, a 20-digit integer / 1.5, and all NULL.

    dev, MySQL -> MySQL: the job succeeds, and the DDL and all values round-trip:

    `d65_0` decimal(65,0), `d50_30` decimal(50,30), `d65_0_u` decimal(65,0) unsigned, `d38_10` decimal(38,10)
    

    This is because MysqlCreateTableSqlBuilder (lines 195-197) reuses column.getSourceType() when the sink is MySQL, so the clamped DECIMAL(38, 18) is never used for the DDL, and the reader passes the BigDecimal through unscaled. The clamp only shows up when a sink builds its DDL from the SeaTunnel type.

    dev, MySQL -> PostgreSQL: this is where it breaks.

    column auto-created PG type
    d65_0 DECIMAL(65,0) numeric(38,18)
    d50_30 DECIMAL(50,30) numeric(38,18)
    d65_0_u DECIMAL(65,0) UNSIGNED numeric(66,0) (wider than MySQL's own 65)
    d38_10 DECIMAL(38,10) numeric(38,10)
    • All rows: the job fails with ERROR: numeric field overflow - A field with precision 38, scale 18 must round to an absolute value less than 10^20 on the 30-digit row.
    • Only the rows that fit (ids 4, 5, 6): the job succeeds, but d50_30 = 0.000000000000000000000000000001 is stored as 0.000000000000000000. Data is lost silently.
    • The only log line is WARN MySqlTypeConverter - DECIMAL will probably cause value overflow., with no column name.

    #12853 (dad4e1244), same jobs: the connector-jdbc jar was built from @Eymenonar's branch, everything else unchanged.

    • MySQL -> PostgreSQL: numeric(65,0), numeric(50,30), numeric(65,0) for the unsigned column, numeric(38,10). All 6 rows are written, and the values match the source exactly (65-digit extremes, the 30-digit fraction, NULLs).
    • MySQL -> MySQL: unchanged, all 6 rows equal to the source (checked with a join on every column).

    So approach A fixes the PostgreSQL case without changing MySQL -> MySQL, and signed and unsigned now give the same type. Two suggestions for #12853:

    1. The tests could cover a non-MySQL target, since MySQL -> MySQL passed before the fix too. For example, assert the reconvert output of the PostgreSQL converter for the converted column, or add an E2E MySQL -> PostgreSQL case.
    2. The incompatible-changes entry should say that MySQL -> MySQL auto-create was already preserving the declared type, so the visible change is for other sinks and transforms.
  7. changed the title [-][Bug] [Connector-V2] [JDBC] MySQL DECIMAL with precision > 38 is clamped to DECIMAL(38, 18), losing integer digits even for MySQL to MySQL[/-] [+][Bug] [Connector-V2] [JDBC] MySQL DECIMAL with precision > 38 is clamped to DECIMAL(38, 18), losing digits in non-MySQL sinks[/+] on Oct 19, 2026
  8. DanielLeens commented on Oct 19, 2026

    @DanielLeens
    Contributor

    Thank you for running the end-to-end comparison. This materially narrows the affected surface: MySQL-to-MySQL auto-create already preserves the source type, while the data-loss/overflow path is MySQL to a non-MySQL sink whose DDL is derived from the SeaTunnel type.

    I confirmed that #12853 is the single focused implementation PR and that its current Build is successful. Please keep a regression that exercises a non-MySQL target (or its precise generated-type/converter equivalent), and make the incompatible-changes note explicit that the visible behavior change is outside MySQL-to-MySQL. Do not broaden the patch beyond the evidenced MySQL mapping paths.

    Classification: F / Connector-V2 JDBC cross-sink DECIMAL precision tracking.

  9. SEZ9 commented on Oct 20, 2026

    @SEZ9
    Collaborator

    Thanks @zhengxiang378928908-code for running the end-to-end reproduction, and for the correction — noted that MySQL -> MySQL is not affected and that the title and description have been updated.

    Your results confirm the point we settled earlier: DECIMAL(30, 0) itself is never remapped, but a value with 30 integer digits stored in a DECIMAL(65, 0) column cannot fit the 20 integer digits of the clamped DECIMAL(38, 18). On dev at e2957d27a that is exactly the numeric field overflow you hit on the 30-digit row for MySQL -> PostgreSQL, and the silent truncation of 0.000000000000000000000000000001 to 0.000000000000000000 in d50_30 is the fractional side of the same clamp. Your explanation also makes clear why MySQL -> MySQL round-trips: MysqlCreateTableSqlBuilder reuses column.getSourceType() for the DDL, so the clamped SeaTunnel type is never used there, and the defect only surfaces when a sink derives its DDL from the SeaTunnel type.

    Your run against dad4e1244 (numeric(65,0) / numeric(50,30) auto-created on PostgreSQL, all six rows matching the source, MySQL -> MySQL unchanged) is the evidence I wanted for approach A. Thanks to @Eymenonar for taking the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions