Repository navigation
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.
- Integer digits are cut to 20.
DECIMAL(65, 0)becomesDECIMAL(38, 18), which has room for only 20 integer digits. A value with 30 integer digits stored in aDECIMAL(65, 0)column no longer fits, even though the column needs no scale at all. (Corrected: a column declaredDECIMAL(30, 0)is not affected, because the clamp only applies whenp > 38.) - Fraction digits above 18 are cut.
DECIMAL(50, 30)becomes scale 18. - The declared type no longer matches the values. The JDBC row converter reads the value with
getBigDecimaland does not rescale it (AbstractJdbcRowConverter,case DECIMAL), so a row can carry e.g. a 26-digit integer while the column type saysDECIMAL(38, 18). The mismatch shows up later in the sink, far from its cause. It even breaks MySQL -> MySQL.Corrected: MySQL -> MySQL is not affected. When both sides are MySQL,MysqlCreateTableSqlBuilderreuses the column's source type (decimal(65,0),decimal(50,30)) instead of the converted type, and the reader passes theBigDecimalthrough 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 getsNUMERIC(38, 18): rows with more than 20 integer digits fail withnumeric field overflow, and fraction digits beyond 18 are rounded silently (0.000000000000000000000000000001is stored as0, job reports success).- Signed and unsigned behave differently.
DECIMAL UNSIGNEDis not clamped:DECIMAL(p, s) UNSIGNEDbecomesDECIMAL(p + 1, s), soDECIMAL(65, 0) UNSIGNEDbecomesDECIMAL(66, 0)while the signedDECIMAL(65, 0)becomesDECIMAL(38, 18). - The only signal is a WARN. The log line has no column name or target type in it, and
GenericTypeConverterdoes the same clamp without any log at all.
The same p > 38 -> (38, 18) clamp exists in:
MySqlTypeConverter(also used by MySQL-CDC throughMySqlTypeUtils)OceanBaseMySqlTypeConverterGenericTypeConverter
(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)toDECIMAL(p, s)as PostgreSQL already does, and leave narrowing to each sink'sreconvert. 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 forp > 38, so it needs anincompatible-changes.mdentry. - 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, butDECIMAL(65, 0)would at least becomeDECIMAL(38, 0)instead ofDECIMAL(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 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.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).
Running Command
./bin/seatunnel.sh --config mysql_wide_decimal.conf -m localError 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
- I agree to follow this project's Code of Conduct
Activity
DanielLeens commentedon Oct 17, 2026
Thank you for separating this from the Spark-specific work in #12814. The current
devpaths do clamp signed MySQL DECIMAL values above 38 toDECIMAL(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)andDECIMAL(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.Eymenonar commentedon Oct 17, 2026
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.
SEZ9 commentedon Oct 18, 2026
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 declaredDECIMAL(30, 0)is never remapped. Did you mean a value with 30 integer digits stored in aDECIMAL(65, 0)column, which would indeed not fit the 20 integer digits ofDECIMAL(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 sameDECIMAL(38, 18)as today. If the declared type is kept (A), anincompatible-changes.mdentry 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.
zhengxiang378928908-code commentedon Oct 18, 2026
Thanks @SEZ9, you're right.
DECIMAL(30, 0)is never remapped; I meant a value with 30 integer digits stored in aDECIMAL(65, 0)column, which doesn't fit the 20 integer digits ofDECIMAL(38, 18). I've corrected the description. Also agreed that B doesn't helpDECIMAL(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.
SEZ9 commentedon Oct 19, 2026
@zhengxiang378928908-code thanks for the correction — that framing is right: a
DECIMAL(65, 0)column holding 30 integer digits cannot survive the remap toDECIMAL(38, 18), which only leaves 20 integer digits, andDECIMAL(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 theDECIMAL(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)andDECIMAL(50, 30)so we can confirm the DDL and values round-trip.@Eymenonar, for the PR please make sure it:
DECIMAL(38, 18);DECIMAL(65, 0)andDECIMAL(50, 30)with tests;DECIMAL(38, 18)output.Please link the PR here once it is up so we can track it against this issue.
zhengxiang378928908-code commentedon Oct 19, 2026
@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,
devate2957d27a(starter + connector-jdbc built from it), MySQL 8.0.46 (strict mode), PostgreSQL 16. Auto-created sink tables (RECREATE_SCHEMA). Source table: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:
This is because
MysqlCreateTableSqlBuilder(lines 195-197) reusescolumn.getSourceType()when the sink is MySQL, so the clampedDECIMAL(38, 18)is never used for the DDL, and the reader passes theBigDecimalthrough unscaled. The clamp only shows up when a sink builds its DDL from the SeaTunnel type.dev, MySQL -> PostgreSQL: this is where it breaks.
d65_0DECIMAL(65,0)numeric(38,18)d50_30DECIMAL(50,30)numeric(38,18)d65_0_uDECIMAL(65,0) UNSIGNEDnumeric(66,0)(wider than MySQL's own 65)d38_10DECIMAL(38,10)numeric(38,10)ERROR: numeric field overflow - A field with precision 38, scale 18 must round to an absolute value less than 10^20on the 30-digit row.d50_30 = 0.000000000000000000000000000001is stored as0.000000000000000000. Data is lost silently.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.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).So approach A fixes the PostgreSQL case without changing MySQL -> MySQL, and signed and unsigned now give the same type. Two suggestions for #12853:
reconvertoutput of the PostgreSQL converter for the converted column, or add an E2E MySQL -> PostgreSQL case.incompatible-changesentry should say that MySQL -> MySQL auto-create was already preserving the declared type, so the visible change is for other sinks and transforms.[-][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[/+]DanielLeens commentedon Oct 19, 2026
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.
SEZ9 commentedon Oct 20, 2026
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 aDECIMAL(65, 0)column cannot fit the 20 integer digits of the clampedDECIMAL(38, 18). Ondevate2957d27athat is exactly the numeric field overflow you hit on the 30-digit row for MySQL -> PostgreSQL, and the silent truncation of0.000000000000000000000000000001to0.000000000000000000ind50_30is the fractional side of the same clamp. Your explanation also makes clear why MySQL -> MySQL round-trips:MysqlCreateTableSqlBuilderreusescolumn.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.