DanielLeens opened a new issue, #13511: URL: https://github.com/apache/seatunnel/issues/13511
## Problem The SQL Server JDBC sink loses the declared DECIMAL scale when binding a null value. With alternating null/non-null decimals, Microsoft JDBC changes parameter declarations inside an executeBatch call, fragmenting batches and repeatedly preparing statements. Data remains correct, but throughput is substantially lower than DataX on the same fixture. This is a longstanding binding behavior, rather than a new data-correctness regression. ## Reproduced environment - SeaTunnel dev: `ee0fb0d72f67edbcd6caf08360fd354fa68e002f`. - DataX master: `5993b26cda90f3e6a4a2fd2e42843efeb770ab3d`. - MySQL 8.0.35 source; SQL Server 2019 CU18 target; both tools and both databases run on one Linux host, using loopback JDBC connections. - Same Temurin 11.0.33.1 JRE, 1 GiB client heap, MySQL Connector/J 8.0.33, Microsoft JDBC 9.4.1.jre8. - One source split and one reader/writer; ordinary INSERT, batch size 1,000, manual commit after every batch, retries disabled. SeaTunnel BATCH checkpointing is disabled by omitting env.checkpoint.interval. - 1,000,000 rows with 19 mixed columns: integer types including values above 2^53, DECIMAL(20,4), REAL/DOUBLE, normalized 0/1 small integers, ASCII/Unicode/empty/null strings, DATE/TIME(0)/DATETIME2(3), 32-byte binary values and long Unicode text. - Approximately 1/17 nulls per non-key column. Each run is reconciled against the canonical source, by primary key and every typed field. DataX dirty records and per-row fallback are rejected. ## Three alternating full-job trials Both actual tool entry points are used: DataX Engine and SeaTunnelClient local mode. These times include process/engine startup and shutdown. A 100,000-row warm-up precedes the measured trials. | Round | DataX seconds | SeaTunnel seconds | DataX / SeaTunnel throughput | Exact values | | --- | ---: | ---: | ---: | --- | | 1 | 51.546 | 91.714 | 1.779x | 1,000,000 x 19 matched | | 2 | 51.557 | 89.919 | 1.744x | 1,000,000 x 19 matched | | 3 | 51.620 | 89.478 | 1.733x | 1,000,000 x 19 matched | ## JDBC-component isolation A separate, warmed comparison uses the actual CommonRdbmsReader, the actual SqlServerWriter Task/CommonRdbmsWriter, and the actual SeaTunnel converter/JdbcOutputFormat. No engine scheduler or transport is included in this comparison. Both writers use the same JDBC drivers, equivalent INSERT statements and explicit commit-on-batch boundaries. | Round | DataX seconds | SeaTunnel seconds | Ratio | Commits / rollbacks per tool | | --- | ---: | ---: | ---: | --- | | 1 | 48.733 | 84.244 | 1.729x | 1,000 / 0; all 19 fields matched | | 2 | 49.084 | 84.618 | 1.724x | 1,000 / 0; all 19 fields matched | | 3 | 48.828 | 83.962 | 1.720x | 1,000 / 0; all 19 fields matched | The gap therefore also exists at the JDBC component boundary. ## Root-cause evidence With the actual Microsoft JDBC 9.4.1 driver, inspecting diagnostic batch parameter declarations for the sequence null, decimal, null, decimal, null showed: ```text Current untyped null: nvarchar(4000), decimal(38,4), decimal(38,0), decimal(38,4), decimal(38,0) Scaled decimal null: decimal(38,4), decimal(38,4), decimal(38,4), decimal(38,4), decimal(38,4) DataX string binding: nvarchar(4000), nvarchar(4000), nvarchar(4000), nvarchar(4000), nvarchar(4000) ``` The diagnostic round-trip also verified negative and high-precision decimals, including a value with 20 significant digits. Driver-private introspection was used only in this diagnostic, never in timed hot paths or production code. SeaTunnel binds non-null decimals with setBigDecimal, but SqlserverJdbcRowConverter falls back to setObject(index, null) for non-binary nulls. DataX CommonRdbmsWriter instead binds numeric values, including nulls, with setString. This keeps the DataX parameter declaration stable; SeaTunnel should retain its typed decimal values and preserve their scale for nulls. A task-local causal intervention changed only SQL Server DECIMAL-null binding to setObject(index, null, Types.DECIMAL, declaredScale). One additional 1,000,000-row component run took 51.468 seconds, compared with the original 83.962–84.618 seconds. All 19 fields matched and the writer performed exactly 1,000 commits and zero rollbacks. This is an isolation result; final production-patch validation will be reported in the PR. ## History and duplicate checks - Initial SQL Server support #2646 used JdbcSink -> JdbcUtils.setRecordToStatement(st, null, row), which bound values through setObject without decimal scale. - #4917 added the explicit SQL Server converter null branch, also using setObject(index, null). - #10626 introduced the current null hook and fixed binary-like nulls; it preserved the existing untyped behavior for non-binary fields. - Open #10099 adds direct SQL Server bulk-copy support. That is a separate path: this reproduction uses ordinary JDBC batching with useBulkCopyForBatchInsert=false in both tools. - Open #10573 adds SQL Server test coverage and does not implement this binding fix. - Open/closed PRs and issues were searched for SQL Server decimal/null/batch/performance objectives before proposing implementation; no same-purpose fix was found. ## Expected fix and acceptance - Preserve the logical decimal scale when binding SQL Server DECIMAL nulls, using standard JDBC APIs. - Keep non-null decimal binding, existing binary-null handling, other dialects, APIs and configuration defaults unchanged. - Retain legacy null handling for logical scales that SQL Server cannot represent, avoiding new errors for existing cross-database configurations. - Extend the existing SQL Server converter tests and SQL Server JDBC integration test; update English/Chinese SQL Server sink documentation. - Verify actual SQL Server round-trips and batch fragmentation, and rerun alternating million-row full jobs with complete value reconciliation before claiming the performance gap is closed. ## Source references - [SeaTunnel SQL Server converter](https://github.com/apache/seatunnel/blob/ee0fb0d72f67edbcd6caf08360fd354fa68e002f/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/sqlserver/SqlserverJdbcRowConverter.java). - [DataX JDBC writer](https://github.com/alibaba/DataX/blob/5993b26cda90f3e6a4a2fd2e42843efeb770ab3d/plugin-rdbms-util/src/main/java/com/alibaba/datax/plugin/rdbms/writer/CommonRdbmsWriter.java). - [Initial SQL Server support](https://github.com/apache/seatunnel/pull/2646), [converter changes](https://github.com/apache/seatunnel/pull/4917), [binary-null fix](https://github.com/apache/seatunnel/pull/10626). -- 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]
