This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/seatunnel.git
The following commit(s) were added to refs/heads/dev by this push:
new c6d24b88dc5 [Improve][Connector-V2] Preserve SQL Server decimal null
scales in generated DML (#13513)
c6d24b88dc5 is described below
commit c6d24b88dc54cc83435142fa9c44b66d2c1eb86b
Author: Daniel <[email protected]>
AuthorDate: Mon Nov 30 12:45:27 2026 +0000
[Improve][Connector-V2] Preserve SQL Server decimal null scales in
generated DML (#13513)
---
docs/en/connectors/sink/SqlServer.md | 4 +
docs/zh/connectors/sink/SqlServer.md | 4 +
.../jdbc/internal/JdbcOutputFormatBuilder.java | 23 +-
.../sqlserver/SqlserverDmlRowConverter.java | 67 +++++
.../connectors/seatunnel/jdbc/JdbcSqlServerIT.java | 334 ++++++++++++++++++++-
5 files changed, 418 insertions(+), 14 deletions(-)
diff --git a/docs/en/connectors/sink/SqlServer.md
b/docs/en/connectors/sink/SqlServer.md
index f8ea96ceb1f..aee3e258895 100644
--- a/docs/en/connectors/sink/SqlServer.md
+++ b/docs/en/connectors/sink/SqlServer.md
@@ -69,6 +69,10 @@ semantics (using XA transaction guarantee).
| BINARY<br />VARBINARY<br />IMAGE<br />TIMESTAMP | BYTES
|
| UNKNOWN | Not
supported yet
|
+## Nullable decimal columns
+
+For automatically generated sink SQL, null decimal values retain the scale
declared by the SeaTunnel decimal type when destination metadata identifies a
DECIMAL or NUMERIC column and the logical scale is between 0 and 38. This
prevents Microsoft JDBC from switching parameter declarations to scale zero and
fragmenting batches when null and non-null decimals alternate. Other
destination types, missing destination type metadata and unsupported logical
scales retain their previous null bindi [...]
+
## Sink Options
| Name | Type | Required | Default |
Description
|
diff --git a/docs/zh/connectors/sink/SqlServer.md
b/docs/zh/connectors/sink/SqlServer.md
index 7b872cff078..29049f5a429 100644
--- a/docs/zh/connectors/sink/SqlServer.md
+++ b/docs/zh/connectors/sink/SqlServer.md
@@ -67,6 +67,10 @@ import ChangeLog from '../changelog/connector-jdbc.md';
| BINARY<br />VARBINARY<br />IMAGE<br />TIMESTAMP | BYTES
|
| UNKNOWN | 尚未支持
|
+## 可空 decimal 列
+
+使用自动生成的写入 SQL 时,若目标列元数据明确为 DECIMAL 或 NUMERIC,且逻辑 scale 为 0~38,decimal NULL 会保留
SeaTunnel 类型声明的 scale,避免 Microsoft JDBC 驱动在 NULL 与非 NULL 之间切换到 scale 为 0
的参数声明并拆分批次。其他目标类型、缺少目标类型元数据或来源 scale 超出该范围时,NULL 继续使用原有绑定。无需新增配置。自定义 SQL
保留原有参数绑定,避免改变 `ISNULL` 等表达式的类型推断;非 NULL 数值也保持原有绑定方式。
+
## 接收器选项
| 名称 | 类型 | 是否必填 | 默认值 | 描述
|
diff --git
a/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/JdbcOutputFormatBuilder.java
b/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/JdbcOutputFormatBuilder.java
index 61991001474..71dccd8cb79 100644
---
a/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/JdbcOutputFormatBuilder.java
+++
b/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/JdbcOutputFormatBuilder.java
@@ -27,6 +27,8 @@ import
org.apache.seatunnel.connectors.seatunnel.jdbc.internal.connection.JdbcCo
import
org.apache.seatunnel.connectors.seatunnel.jdbc.internal.converter.JdbcRowConverter;
import
org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.DatabaseIdentifier;
import
org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialect;
+import
org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.sqlserver.SqlServerDialect;
+import
org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.sqlserver.SqlserverDmlRowConverter;
import
org.apache.seatunnel.connectors.seatunnel.jdbc.internal.executor.BufferReducedBatchStatementExecutor;
import
org.apache.seatunnel.connectors.seatunnel.jdbc.internal.executor.BufferedBatchStatementExecutor;
import
org.apache.seatunnel.connectors.seatunnel.jdbc.internal.executor.CopyManagerBatchStatementExecutor;
@@ -123,6 +125,17 @@ public class JdbcOutputFormatBuilder {
commitOnFlush);
}
+ /**
+ * Selects scaled decimal null binding only for generated writes of the
exact built-in SQL
+ * Server dialect. Custom SQL, DELETE and dialect subclasses retain their
existing converters.
+ */
+ private static JdbcRowConverter getGeneratedDmlRowConverter(JdbcDialect
dialect) {
+ // Custom SQL and dialect subclasses retain their existing conversion
contract.
+ return dialect.getClass() == SqlServerDialect.class
+ ? new SqlserverDmlRowConverter()
+ : dialect.getRowConverter();
+ }
+
private static JdbcBatchStatementExecutor<SeaTunnelRow>
createSimpleBufferedExecutor(
JdbcDialect dialect,
JdbcSinkConfig jdbcSinkConfig,
@@ -134,7 +147,7 @@ public class JdbcOutputFormatBuilder {
dialect.getInsertIntoStatement(database, table,
tableSchema.getFieldNames());
insertSQL = applyOracleAppendValuesHintIfNeeded(jdbcSinkConfig,
insertSQL);
return createSimpleBufferedExecutor(
- insertSQL, tableSchema, databaseTableSchema,
dialect.getRowConverter());
+ insertSQL, tableSchema, databaseTableSchema,
getGeneratedDmlRowConverter(dialect));
}
private static JdbcBatchStatementExecutor<SeaTunnelRow>
createSimpleBufferedExecutor(
@@ -217,7 +230,7 @@ public class JdbcOutputFormatBuilder {
upsertSQL.get(),
tableSchema,
databaseTableSchema,
- dialect.getRowConverter());
+ getGeneratedDmlRowConverter(dialect));
}
return createInsertOrUpdateByQueryExecutor(
dialect,
@@ -271,7 +284,7 @@ public class JdbcOutputFormatBuilder {
tableSchema.getFieldNames()),
tableSchema,
databaseTableSchema,
- dialect.getRowConverter());
+ getGeneratedDmlRowConverter(dialect));
}
private static JdbcBatchStatementExecutor<SeaTunnelRow>
createInsertOrUpdateExecutor(
@@ -302,7 +315,7 @@ public class JdbcOutputFormatBuilder {
tableSchema.getFieldNames()),
tableSchema,
databaseTableSchema,
- dialect.getRowConverter());
+ getGeneratedDmlRowConverter(dialect));
}
private static JdbcBatchStatementExecutor<SeaTunnelRow>
createInsertOrUpdateByQueryExecutor(
@@ -341,7 +354,7 @@ public class JdbcOutputFormatBuilder {
keyExtractor,
tableSchema,
databaseTableSchema,
- dialect.getRowConverter());
+ getGeneratedDmlRowConverter(dialect));
}
private static JdbcBatchStatementExecutor<SeaTunnelRow>
createDeleteExecutor(
diff --git
a/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/sqlserver/SqlserverDmlRowConverter.java
b/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/sqlserver/SqlserverDmlRowConverter.java
new file mode 100644
index 00000000000..fe86946ad0b
--- /dev/null
+++
b/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/sqlserver/SqlserverDmlRowConverter.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package
org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.sqlserver;
+
+import org.apache.seatunnel.api.table.type.DecimalType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+
+import javax.annotation.Nullable;
+
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Types;
+
+/**
+ * Preserves representable logical decimal scales for confirmed decimal
destinations in generated
+ * SQL Server DML. Other nulls and all non-null values retain the superclass
binding contract.
+ */
+public final class SqlserverDmlRowConverter extends SqlserverJdbcRowConverter {
+
+ /**
+ * A scale-zero null changes the driver's parameter declaration and
fragments decimal batches.
+ * Custom SQL keeps the original converter because expressions can depend
on parameter types.
+ */
+ @Override
+ protected void setNullToStatementByDataType(
+ PreparedStatement statement,
+ SeaTunnelDataType<?> seaTunnelDataType,
+ int statementIndex,
+ @Nullable String sourceType)
+ throws SQLException {
+ // Only known decimal targets can safely accept a typed decimal null.
In particular,
+ // an untyped null can reach DATE columns where a DECIMAL null is
rejected.
+ boolean decimalTarget =
+ sourceType != null
+ &&
(sourceType.equals(SqlServerTypeConverter.SQLSERVER_DECIMAL)
+ || sourceType.startsWith(
+
SqlServerTypeConverter.SQLSERVER_DECIMAL + "(")
+ ||
sourceType.equals(SqlServerTypeConverter.SQLSERVER_NUMERIC)
+ || sourceType.startsWith(
+
SqlServerTypeConverter.SQLSERVER_NUMERIC + "("));
+ if (decimalTarget && seaTunnelDataType instanceof DecimalType) {
+ int scale = ((DecimalType) seaTunnelDataType).getScale();
+ // Logical types can carry scales outside SQL Server's supported
range.
+ if (scale >= 0 && scale <= SqlServerTypeConverter.MAX_PRECISION) {
+ statement.setObject(statementIndex, null, Types.DECIMAL,
scale);
+ return;
+ }
+ }
+ super.setNullToStatementByDataType(
+ statement, seaTunnelDataType, statementIndex, sourceType);
+ }
+}
diff --git
a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-part-3/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/JdbcSqlServerIT.java
b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-part-3/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/JdbcSqlServerIT.java
index 9dece9ca69d..91e3f653c5e 100644
---
a/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-part-3/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/JdbcSqlServerIT.java
+++
b/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-jdbc-e2e/connector-jdbc-e2e-part-3/src/test/java/org/apache/seatunnel/connectors/seatunnel/jdbc/JdbcSqlServerIT.java
@@ -21,14 +21,23 @@ import
org.apache.seatunnel.shade.com.google.common.collect.Lists;
import org.apache.seatunnel.shade.org.apache.commons.lang3.tuple.Pair;
import org.apache.seatunnel.api.table.catalog.CatalogTable;
+import org.apache.seatunnel.api.table.catalog.PhysicalColumn;
import org.apache.seatunnel.api.table.catalog.TablePath;
import org.apache.seatunnel.api.table.catalog.TableSchema;
import org.apache.seatunnel.api.table.type.BasicType;
+import org.apache.seatunnel.api.table.type.DecimalType;
import org.apache.seatunnel.api.table.type.LocalTimeType;
+import org.apache.seatunnel.api.table.type.RowKind;
import org.apache.seatunnel.api.table.type.SeaTunnelRow;
import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException;
import
org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.sqlserver.SqlServerCatalog;
import
org.apache.seatunnel.connectors.seatunnel.jdbc.catalog.sqlserver.SqlServerURLParser;
+import
org.apache.seatunnel.connectors.seatunnel.jdbc.config.JdbcConnectionConfig;
+import org.apache.seatunnel.connectors.seatunnel.jdbc.config.JdbcSinkConfig;
+import
org.apache.seatunnel.connectors.seatunnel.jdbc.internal.JdbcOutputFormat;
+import
org.apache.seatunnel.connectors.seatunnel.jdbc.internal.JdbcOutputFormatBuilder;
+import
org.apache.seatunnel.connectors.seatunnel.jdbc.internal.connection.SimpleJdbcConnectionProvider;
+import
org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.sqlserver.SqlServerDialect;
import org.apache.seatunnel.e2e.common.TestSuiteBase;
import org.apache.seatunnel.e2e.common.container.TestContainer;
@@ -42,6 +51,8 @@ import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.DockerLoggerFactory;
import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.LocalDate;
@@ -50,6 +61,7 @@ import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -187,15 +199,6 @@ public class JdbcSqlServerIT extends AbstractJdbcIT {
VIEW_COLUMNS);
}
- private String createViewSql() {
- return "CREATE OR ALTER VIEW "
- + buildTableInfoWithSchema(SQLSERVER_SCHEMA, VIEW_SOURCE)
- + " AS SELECT "
- + String.join(", ", VIEW_COLUMNS)
- + " FROM "
- + buildTableInfoWithSchema(SQLSERVER_SCHEMA, SQLSERVER_SOURCE);
- }
-
@Override
JdbcCase getJdbcCase() {
Map<String, String> containerEnv = new HashMap<>();
@@ -329,6 +332,272 @@ public class JdbcSqlServerIT extends AbstractJdbcIT {
return Pair.of(fieldNames, rows);
}
+ /**
+ * Scale-zero null declarations split a batch into many round trips even
though values are
+ * correct. Count server response packets instead of asserting a
machine-dependent duration.
+ */
+ @Test
+ public void testNullableDecimalBatchRetainsScale() throws Exception {
+ String table = "dbo.decimal_batch_" +
UUID.randomUUID().toString().replace("-", "");
+ connection.setAutoCommit(false);
+ try (Statement statement = connection.createStatement()) {
+ statement.execute(
+ "CREATE TABLE "
+ + table
+ + " (id INT PRIMARY KEY, amount DECIMAL(20,4),
fractional DECIMAL(38,38), over_scale DECIMAL(20,4), negative_scale
DECIMAL(20,4))");
+ connection.commit();
+ }
+ TableSchema schema =
+ TableSchema.builder()
+ .column(
+ PhysicalColumn.builder()
+ .name("id")
+ .dataType(BasicType.INT_TYPE)
+ .nullable(false)
+ .build())
+ .column(
+ PhysicalColumn.builder()
+ .name("amount")
+ .dataType(new DecimalType(20, 4))
+ .sourceType("DECIMAL(20,4)")
+ .build())
+ .column(
+ PhysicalColumn.builder()
+ .name("fractional")
+ .dataType(new DecimalType(38, 38))
+ .sourceType("DECIMAL(38,38)")
+ .build())
+ .column(
+ PhysicalColumn.builder()
+ .name("over_scale")
+ .dataType(new DecimalType(76, 39))
+ .sourceType("DECIMAL(20,4)")
+ .build())
+ .column(
+ PhysicalColumn.builder()
+ .name("negative_scale")
+ .dataType(new DecimalType(76, -2))
+ .sourceType("NUMERIC(20,4)")
+ .build())
+ .build();
+ String[] modes = {"insert", "merge", "fallback"};
+ for (int phase = 0; phase < modes.length; phase++) {
+ JdbcConnectionConfig connectionConfig =
decimalBatchConnectionConfig();
+ SimpleJdbcConnectionProvider provider =
+ new SimpleJdbcConnectionProvider(connectionConfig);
+ JdbcSinkConfig config =
+ JdbcSinkConfig.builder()
+ .jdbcConnectionConfig(connectionConfig)
+ .database(connection.getCatalog())
+ .table(table)
+ .primaryKeys(
+ phase == 0
+ ? Collections.emptyList()
+ : Collections.singletonList("id"))
+ .enableUpsert("merge".equals(modes[phase]))
+ .build();
+ JdbcOutputFormat format =
+ new JdbcOutputFormatBuilder(
+ new SqlServerDialect(), provider, config,
schema, schema)
+ .commitOnFlush(true)
+ .build();
+ try (AutoCloseable cleanup = format::close) {
+ format.open();
+ long before =
sqlServerResponsePacketCount(provider.getConnection());
+ for (int id = 1; id <= 1000; id++) {
+ SeaTunnelRow row = decimalBatchRow(id, phase);
+ // With upsert disabled, row kind chooses INSERT versus
UPDATE.
+ if (phase > 0) {
+ row.setRowKind(RowKind.UPDATE_AFTER);
+ }
+ format.writeRecord(row);
+ }
+ format.flush();
+ long packets =
sqlServerResponsePacketCount(provider.getConnection()) - before;
+ if (phase == 0) {
+ Assertions.assertTrue(
+ packets <= 80,
+ "Ten decimal batches should not fragment at null
transitions; response packets="
+ + packets);
+ }
+ }
+ try (Statement statement = connection.createStatement();
+ ResultSet rows =
+ statement.executeQuery(
+ "SELECT
id,amount,fractional,over_scale,negative_scale FROM "
+ + table
+ + " ORDER BY id")) {
+ for (int id = 1; id <= 1000; id++) {
+ Assertions.assertTrue(rows.next(), "Missing decimal row "
+ id);
+ SeaTunnelRow expected = decimalBatchRow(id, phase);
+ Assertions.assertEquals(id, rows.getInt(1));
+ Assertions.assertEquals(expected.getField(1),
rows.getBigDecimal(2));
+ Assertions.assertEquals(expected.getField(2),
rows.getBigDecimal(3));
+ Assertions.assertNull(rows.getBigDecimal(4));
+ Assertions.assertNull(rows.getBigDecimal(5));
+ }
+ Assertions.assertFalse(rows.next(), "Unexpected decimal rows");
+ }
+ }
+ }
+
+ /**
+ * Protects custom expression inference even when destination metadata is
supplied to the
+ * builder. Generated decimal null typing must not change the accepted
ISNULL fallback result.
+ */
+ @Test
+ public void testCustomSqlPreservesDecimalNullInference() throws Exception {
+ String table = "dbo.decimal_custom_" +
UUID.randomUUID().toString().replace("-", "");
+ try (Statement statement = connection.createStatement()) {
+ statement.execute(
+ "CREATE TABLE "
+ + table
+ + " (id INT PRIMARY KEY, formatted NVARCHAR(64),
amount DECIMAL(20,4))");
+ connection.commit();
+ }
+ TableSchema schema =
+ TableSchema.builder()
+ .column(
+ PhysicalColumn.builder()
+ .name("id")
+ .dataType(BasicType.INT_TYPE)
+ .build())
+ .column(
+ PhysicalColumn.builder()
+ .name("amount")
+ .dataType(new DecimalType(20, 4))
+ .sourceType("DECIMAL(20,4)")
+ .build())
+ .build();
+ JdbcConnectionConfig connectionConfig = decimalBatchConnectionConfig();
+ JdbcSinkConfig config =
+ JdbcSinkConfig.builder()
+ .jdbcConnectionConfig(connectionConfig)
+ .table(table)
+ .simpleSql(
+ "INSERT INTO "
+ + table
+ + " (id,formatted) VALUES
(:id,ISNULL(:amount,'fallback'))")
+ .build();
+ JdbcOutputFormat format =
+ new JdbcOutputFormatBuilder(
+ new SqlServerDialect(),
+ new
SimpleJdbcConnectionProvider(connectionConfig),
+ config,
+ schema,
+ schema)
+ .commitOnFlush(true)
+ .build();
+ try (AutoCloseable cleanup = format::close) {
+ format.open();
+ for (int id = 1; id <= 3; id++) {
+ format.writeRecord(new SeaTunnelRow(new Object[] {id, null}));
+ }
+ format.flush();
+ }
+ try (Statement statement = connection.createStatement();
+ ResultSet rows =
+ statement.executeQuery(
+ "SELECT id,formatted FROM " + table + " ORDER
BY id")) {
+ for (int id = 1; id <= 3; id++) {
+ Assertions.assertTrue(rows.next());
+ Assertions.assertEquals(id, rows.getInt(1));
+ Assertions.assertEquals("fallback", rows.getString(2));
+ }
+ Assertions.assertFalse(rows.next());
+ }
+ }
+
+ /**
+ * Preserves accepted logical decimal null writes to DATE and unknown
destination types. Only
+ * confirmed decimal destinations may receive the generated statement's
scaled decimal null.
+ */
+ @Test
+ public void testGeneratedSqlPreservesNullForDifferentTargetType() throws
Exception {
+ String table = "dbo.decimal_null_target_" +
UUID.randomUUID().toString().replace("-", "");
+ try (Statement statement = connection.createStatement()) {
+ statement.execute(
+ "CREATE TABLE "
+ + table
+ + " (id INT PRIMARY KEY, as_date DATE,
unknown_date DATE)");
+ connection.commit();
+ }
+ TableSchema sourceSchema =
+ TableSchema.builder()
+ .column(
+ PhysicalColumn.builder()
+ .name("id")
+ .dataType(BasicType.INT_TYPE)
+ .build())
+ .column(
+ PhysicalColumn.builder()
+ .name("as_date")
+ .dataType(new DecimalType(20, 4))
+ .build())
+ .column(
+ PhysicalColumn.builder()
+ .name("unknown_date")
+ .dataType(new DecimalType(20, 4))
+ .build())
+ .build();
+ TableSchema targetSchema =
+ TableSchema.builder()
+ .column(
+ PhysicalColumn.builder()
+ .name("id")
+ .dataType(BasicType.INT_TYPE)
+ .sourceType("INT")
+ .build())
+ .column(
+ PhysicalColumn.builder()
+ .name("as_date")
+
.dataType(LocalTimeType.LOCAL_DATE_TYPE)
+ .sourceType("DATE")
+ .build())
+ .column(
+ PhysicalColumn.builder()
+ .name("unknown_date")
+
.dataType(LocalTimeType.LOCAL_DATE_TYPE)
+ .build())
+ .build();
+ JdbcConnectionConfig connectionConfig = decimalBatchConnectionConfig();
+ JdbcSinkConfig config =
+ JdbcSinkConfig.builder()
+ .jdbcConnectionConfig(connectionConfig)
+ .database(connection.getCatalog())
+ .table(table)
+ .enableUpsert(false)
+ .build();
+ JdbcOutputFormat format =
+ new JdbcOutputFormatBuilder(
+ new SqlServerDialect(),
+ new
SimpleJdbcConnectionProvider(connectionConfig),
+ config,
+ sourceSchema,
+ targetSchema)
+ .commitOnFlush(true)
+ .build();
+ try (AutoCloseable cleanup = format::close) {
+ format.open();
+ for (int id = 1; id <= 3; id++) {
+ format.writeRecord(new SeaTunnelRow(new Object[] {id, null,
null}));
+ }
+ format.flush();
+ }
+ try (Statement statement = connection.createStatement();
+ ResultSet rows =
+ statement.executeQuery(
+ "SELECT id,as_date,unknown_date FROM " + table
+ " ORDER BY id")) {
+ for (int id = 1; id <= 3; id++) {
+ Assertions.assertTrue(rows.next());
+ Assertions.assertEquals(id, rows.getInt(1));
+ Assertions.assertNull(rows.getDate(2));
+ Assertions.assertNull(rows.getDate(3));
+ }
+ Assertions.assertFalse(rows.next());
+ }
+ }
+
@Override
GenericContainer<?> initContainer() {
DockerImageName imageName = DockerImageName.parse(SQLSERVER_IMAGE);
@@ -505,4 +774,51 @@ public class JdbcSqlServerIT extends AbstractJdbcIT {
}
}
}
+
+ private String createViewSql() {
+ return "CREATE OR ALTER VIEW "
+ + buildTableInfoWithSchema(SQLSERVER_SCHEMA, VIEW_SOURCE)
+ + " AS SELECT "
+ + String.join(", ", VIEW_COLUMNS)
+ + " FROM "
+ + buildTableInfoWithSchema(SQLSERVER_SCHEMA, SQLSERVER_SOURCE);
+ }
+
+ private JdbcConnectionConfig decimalBatchConnectionConfig() {
+ return JdbcConnectionConfig.builder()
+ .url(jdbcCase.getJdbcUrl().replace(HOST, dbServer.getHost()))
+ .driverName(DRIVER_CLASS)
+ .username(jdbcCase.getUserName())
+ .password(jdbcCase.getPassword())
+ .autoCommit(false)
+ .batchSize(100)
+ .batchIntervalMs(0)
+ .maxRetries(0)
+ .build();
+ }
+
+ /**
+ * Exercises independent null transitions, high-precision values and the
supported scale limit.
+ */
+ private SeaTunnelRow decimalBatchRow(int id, int phase) {
+ BigDecimal amount = (id + phase) % 2 == 0 ? null : new
BigDecimal("1234567890123456.1234");
+ if (amount != null && (id + phase) % 4 == 3) {
+ amount = amount.negate();
+ }
+ BigDecimal fractional = (id + phase) % 3 == 0 ? null :
BigDecimal.valueOf(id + phase, 38);
+ return new SeaTunnelRow(new Object[] {id, amount, fractional, null,
null});
+ }
+
+ /**
+ * The dedicated connection's response packets expose extra driver round
trips without timing.
+ */
+ private long sqlServerResponsePacketCount(Connection writerConnection)
throws SQLException {
+ try (Statement statement = writerConnection.createStatement();
+ ResultSet result =
+ statement.executeQuery(
+ "SELECT num_writes FROM
sys.dm_exec_connections WHERE session_id=@@SPID")) {
+ Assertions.assertTrue(result.next(), "SQL Server connection
statistics unavailable");
+ return result.getLong(1);
+ }
+ }
}