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 67adb0a279d [Test][Benchmark] Add a JDBC row converter benchmark 
(#13214)
67adb0a279d is described below

commit 67adb0a279d48ce5dc201a820c8007db13d9b1e1
Author: zhiweiniu <[email protected]>
AuthorDate: Tue Nov 17 05:56:00 2026 +0000

    [Test][Benchmark] Add a JDBC row converter benchmark (#13214)
---
 .github/workflows/benchmarks.yml                   |   1 +
 seatunnel-benchmarks/README.md                     |  10 +
 seatunnel-benchmarks/pom.xml                       |   5 +
 .../benchmark/JdbcRowConverterBenchmark.java       |  80 +++++++
 .../benchmark/jdbc/JdbcRowConverterFixture.java    | 233 +++++++++++++++++++++
 5 files changed, 329 insertions(+)

diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml
index 6f55dee946b..a314ac4d97d 100644
--- a/.github/workflows/benchmarks.yml
+++ b/.github/workflows/benchmarks.yml
@@ -46,6 +46,7 @@ on:
           - 'IMapJobStorageBenchmark'
           - 'IMapDagStorageBenchmark'
           - 'IMapWalStorageBenchmark'
+          - 'JdbcRowConverterBenchmark'
         default: 'benchmarks_core'
       custom_benchmarks:
         description: 'Exact JMH selector; overrides the choice. .* may exceed 
240 minutes.'
diff --git a/seatunnel-benchmarks/README.md b/seatunnel-benchmarks/README.md
index 25834cb9384..15d15829bf6 100644
--- a/seatunnel-benchmarks/README.md
+++ b/seatunnel-benchmarks/README.md
@@ -71,6 +71,16 @@ java -jar seatunnel-benchmarks/target/benchmarks.jar 
SeaTunnelRowBenchmark \
   -rff seatunnel-benchmarks/target/benchmark-result.json
 ```
 
+Run only the `JdbcRowConverter` benchmarks.
+
+```bash
+java -jar seatunnel-benchmarks/target/benchmarks.jar JdbcRowConverterBenchmark
+```
+
+The default uses a mixed 20-column row covering booleans, integers, 
floating-point numbers, decimals,
+strings, binary, temporal and NULL values. It measures both conversion 
directions (2 cases).
+Override the row width with `-p columns=40`.
+
 ## Run Zeta full-pipeline benchmarks
 
 ```bash
diff --git a/seatunnel-benchmarks/pom.xml b/seatunnel-benchmarks/pom.xml
index 8a3da5d15ed..6f13a9dccaf 100644
--- a/seatunnel-benchmarks/pom.xml
+++ b/seatunnel-benchmarks/pom.xml
@@ -43,6 +43,11 @@
             <artifactId>seatunnel-format-json</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.seatunnel</groupId>
+            <artifactId>connector-jdbc</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.apache.seatunnel</groupId>
             <artifactId>seatunnel-engine-client</artifactId>
diff --git 
a/seatunnel-benchmarks/src/main/java/org/apache/seatunnel/benchmark/JdbcRowConverterBenchmark.java
 
b/seatunnel-benchmarks/src/main/java/org/apache/seatunnel/benchmark/JdbcRowConverterBenchmark.java
new file mode 100644
index 00000000000..1e820d315f2
--- /dev/null
+++ 
b/seatunnel-benchmarks/src/main/java/org/apache/seatunnel/benchmark/JdbcRowConverterBenchmark.java
@@ -0,0 +1,80 @@
+/*
+ * 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.benchmark;
+
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.benchmark.jdbc.JdbcRowConverterFixture;
+
+import org.openjdk.jmh.Main;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Param;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.Threads;
+
+import java.io.IOException;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.concurrent.TimeUnit;
+
+/** Measures JDBC row conversion and parameter binding with prepared inputs. */
+@Threads(1)
+@Fork(
+        value = 3,
+        jvmArgsAppend = {
+            "-Xms4g",
+            "-Xmx4g",
+            "-XX:+UseG1GC",
+            "-XX:+AlwaysPreTouch",
+            "-XX:+DisableExplicitGC",
+            "-XX:ActiveProcessorCount=4",
+            "-Djava.net.preferIPv4Stack=true"
+        })
+public class JdbcRowConverterBenchmark extends BenchmarkBase {
+
+    @Param({"20"})
+    private int columns;
+
+    private JdbcRowConverterFixture fixture;
+
+    public static void main(String[] args) throws IOException {
+        String[] options = new String[args.length + 1];
+        options[0] = JdbcRowConverterBenchmark.class.getCanonicalName();
+        System.arraycopy(args, 0, options, 1, args.length);
+        Main.main(options);
+    }
+
+    @Setup(Level.Trial)
+    public void setUp() throws SQLException {
+        fixture = new JdbcRowConverterFixture(columns);
+    }
+
+    @Benchmark
+    @OutputTimeUnit(TimeUnit.SECONDS)
+    public SeaTunnelRow toInternal() throws SQLException {
+        return fixture.readRow();
+    }
+
+    @Benchmark
+    @OutputTimeUnit(TimeUnit.SECONDS)
+    public PreparedStatement toExternal() throws SQLException {
+        return fixture.bindRow();
+    }
+}
diff --git 
a/seatunnel-benchmarks/src/main/java/org/apache/seatunnel/benchmark/jdbc/JdbcRowConverterFixture.java
 
b/seatunnel-benchmarks/src/main/java/org/apache/seatunnel/benchmark/jdbc/JdbcRowConverterFixture.java
new file mode 100644
index 00000000000..47f7b1dd7d1
--- /dev/null
+++ 
b/seatunnel-benchmarks/src/main/java/org/apache/seatunnel/benchmark/jdbc/JdbcRowConverterFixture.java
@@ -0,0 +1,233 @@
+/*
+ * 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.benchmark.jdbc;
+
+import org.apache.seatunnel.api.table.catalog.PhysicalColumn;
+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.PrimitiveByteArrayType;
+import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import 
org.apache.seatunnel.connectors.seatunnel.jdbc.internal.converter.AbstractJdbcRowConverter;
+import 
org.apache.seatunnel.connectors.seatunnel.jdbc.internal.converter.JdbcRowConverter;
+
+import java.lang.reflect.Proxy;
+import java.math.BigDecimal;
+import java.sql.Date;
+import java.sql.JDBCType;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.OffsetDateTime;
+import java.util.Arrays;
+import java.util.Collections;
+
+/** Provides a positioned result set and a parameter recorder for the common 
JDBC converter. */
+public final class JdbcRowConverterFixture {
+
+    private static final LocalDate SAMPLE_DATE = LocalDate.of(2026, 4, 2);
+    private static final LocalTime SAMPLE_TIME = LocalTime.of(13, 45, 7);
+    private static final LocalDateTime SAMPLE_TIMESTAMP =
+            SAMPLE_DATE.atTime(SAMPLE_TIME).withNano(123_456_000);
+
+    private static final FieldSample[] FIELD_SAMPLES = {
+        new FieldSample(BasicType.BOOLEAN_TYPE, JDBCType.BOOLEAN, true),
+        new FieldSample(BasicType.BYTE_TYPE, JDBCType.TINYINT, (byte) 42),
+        new FieldSample(BasicType.SHORT_TYPE, JDBCType.SMALLINT, (short) 1009),
+        new FieldSample(BasicType.INT_TYPE, JDBCType.INTEGER, 1009),
+        new FieldSample(BasicType.LONG_TYPE, JDBCType.BIGINT, 10_000_007_123L),
+        new FieldSample(BasicType.FLOAT_TYPE, JDBCType.REAL, 1.25F),
+        new FieldSample(BasicType.DOUBLE_TYPE, JDBCType.DOUBLE, 2.5D),
+        new FieldSample(
+                new DecimalType(18, 4), JDBCType.DECIMAL, new 
BigDecimal("1234567890123.4567")),
+        new FieldSample(BasicType.STRING_TYPE, JDBCType.VARCHAR, 
"customer_0291"),
+        new FieldSample(PrimitiveByteArrayType.INSTANCE, JDBCType.VARBINARY, 
new byte[] {1, 0, -1}),
+        new FieldSample(
+                LocalTimeType.LOCAL_DATE_TYPE,
+                JDBCType.DATE,
+                SAMPLE_DATE,
+                Date.valueOf(SAMPLE_DATE)),
+        new FieldSample(
+                LocalTimeType.LOCAL_TIME_TYPE,
+                JDBCType.TIME,
+                SAMPLE_TIME,
+                Time.valueOf(SAMPLE_TIME)),
+        new FieldSample(
+                LocalTimeType.LOCAL_DATE_TIME_TYPE,
+                JDBCType.TIMESTAMP,
+                SAMPLE_TIMESTAMP,
+                Timestamp.valueOf(SAMPLE_TIMESTAMP)),
+        new FieldSample(
+                LocalTimeType.OFFSET_DATE_TIME_TYPE,
+                JDBCType.TIMESTAMP_WITH_TIMEZONE,
+                OffsetDateTime.parse("2026-04-02T13:45:07.123456+08:00")),
+        new FieldSample(BasicType.STRING_TYPE, JDBCType.VARCHAR, null)
+    };
+
+    private final JdbcRowConverter converter =
+            new AbstractJdbcRowConverter() {
+                @Override
+                public String converterName() {
+                    return "benchmark";
+                }
+            };
+    private final TableSchema tableSchema;
+    private final TableSchema targetTableSchema;
+    private final SeaTunnelRow inputRow;
+    private final PreparedStatement statement;
+    private final ResultSet resultSet;
+
+    public JdbcRowConverterFixture(int columns) throws SQLException {
+        if (columns < 1) {
+            throw new IllegalArgumentException("columns must be positive");
+        }
+
+        TableSchema.Builder schemaBuilder = TableSchema.builder();
+        Object[] fields = new Object[columns];
+        Object[] jdbcValues = new Object[columns];
+        for (int column = 0; column < columns; column++) {
+            FieldSample field = FIELD_SAMPLES[column % FIELD_SAMPLES.length];
+            String name = "c" + column;
+            schemaBuilder.column(
+                    PhysicalColumn.of(
+                            name,
+                            field.type,
+                            64L,
+                            true,
+                            null,
+                            "",
+                            field.jdbcType.getName(),
+                            Collections.emptyMap()));
+            fields[column] = field.rowValue;
+            jdbcValues[column] = field.jdbcValue;
+        }
+        tableSchema = schemaBuilder.build();
+        targetTableSchema = tableSchema.copy();
+        inputRow = new SeaTunnelRow(fields);
+        resultSet = positionedResultSet(fields, jdbcValues);
+
+        Object[] parameters = new Object[columns];
+        Arrays.fill(parameters, new Object());
+        statement = recordingStatement(parameters);
+        bindRow();
+        if (!Arrays.deepEquals(jdbcValues, parameters)
+                || !Arrays.deepEquals(fields, readRow().getFields())) {
+            throw new IllegalStateException("JDBC conversion did not preserve 
the input fields");
+        }
+    }
+
+    public SeaTunnelRow readRow() throws SQLException {
+        return converter.toInternal(resultSet, tableSchema);
+    }
+
+    public PreparedStatement bindRow() throws SQLException {
+        return converter.toExternal(tableSchema, targetTableSchema, inputRow, 
statement);
+    }
+
+    private static ResultSet positionedResultSet(Object[] fields, Object[] 
jdbcValues) {
+        return (ResultSet)
+                Proxy.newProxyInstance(
+                        JdbcRowConverterFixture.class.getClassLoader(),
+                        new Class<?>[] {ResultSet.class},
+                        (proxy, method, args) -> {
+                            switch (method.getName()) {
+                                case "getObject":
+                                    int index = (Integer) args[0] - 1;
+                                    if (args.length == 2 && args[1] instanceof 
Class) {
+                                        // Model the JDBC 4.2 getter for a 
local timestamp.
+                                        return ((Class<?>) 
args[1]).cast(fields[index]);
+                                    }
+                                    return jdbcValues[index];
+                                case "getBoolean":
+                                case "getByte":
+                                case "getShort":
+                                case "getInt":
+                                case "getLong":
+                                case "getFloat":
+                                case "getDouble":
+                                case "getBigDecimal":
+                                case "getString":
+                                case "getBytes":
+                                case "getDate":
+                                case "getTime":
+                                case "getTimestamp":
+                                    return jdbcValues[(Integer) args[0] - 1];
+                                default:
+                                    throw new 
UnsupportedOperationException(method.getName());
+                            }
+                        });
+    }
+
+    private static PreparedStatement recordingStatement(Object[] parameters) {
+        return (PreparedStatement)
+                Proxy.newProxyInstance(
+                        JdbcRowConverterFixture.class.getClassLoader(),
+                        new Class<?>[] {PreparedStatement.class},
+                        (proxy, method, args) -> {
+                            switch (method.getName()) {
+                                case "setBoolean":
+                                case "setByte":
+                                case "setShort":
+                                case "setInt":
+                                case "setLong":
+                                case "setFloat":
+                                case "setString":
+                                case "setDouble":
+                                case "setBigDecimal":
+                                case "setBytes":
+                                case "setDate":
+                                case "setTime":
+                                case "setTimestamp":
+                                case "setObject":
+                                    parameters[(Integer) args[0] - 1] = 
args[1];
+                                    return null;
+                                case "setNull":
+                                    parameters[(Integer) args[0] - 1] = null;
+                                    return null;
+                                default:
+                                    throw new 
UnsupportedOperationException(method.getName());
+                            }
+                        });
+    }
+
+    private static final class FieldSample {
+        private final SeaTunnelDataType<?> type;
+        private final JDBCType jdbcType;
+        private final Object rowValue;
+        private final Object jdbcValue;
+
+        private FieldSample(SeaTunnelDataType<?> type, JDBCType jdbcType, 
Object value) {
+            this(type, jdbcType, value, value);
+        }
+
+        private FieldSample(
+                SeaTunnelDataType<?> type, JDBCType jdbcType, Object rowValue, 
Object jdbcValue) {
+            this.type = type;
+            this.jdbcType = jdbcType;
+            this.rowValue = rowValue;
+            this.jdbcValue = jdbcValue;
+        }
+    }
+}

Reply via email to