This is an automated email from the ASF dual-hosted git repository.

MartijnVisser pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flink-connector-jdbc.git


The following commit(s) were added to refs/heads/main by this push:
     new 6b1c2773 [FLINK-40747][jdbc] PreparedSplitterEnumerator.of(sql) yields 
one split
6b1c2773 is described below

commit 6b1c277396fb6ac96461b3efa02ef5da4a1f6ef9
Author: Martijn Visser <[email protected]>
AuthorDate: Tue Sep 22 10:41:29 2026 +0200

    [FLINK-40747][jdbc] PreparedSplitterEnumerator.of(sql) yields one split
    
    - of(sqlTemplate) builds one empty parameter row instead of an empty matrix
    - SqlSplitterEnumerator unchanged: an empty matrix still gives no split
    
    Generated-by: Claude Code (Fable 5.1)
---
 .../splitter/PreparedSplitterEnumerator.java       |  5 +-
 .../core/datastream/source/JdbcSourceITCase.java   | 20 ++++++
 .../splitter/PreparedSplitterEnumeratorTest.java   | 74 ++++++++++++++++++++++
 3 files changed, 98 insertions(+), 1 deletion(-)

diff --git 
a/flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/core/datastream/source/enumerator/splitter/PreparedSplitterEnumerator.java
 
b/flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/core/datastream/source/enumerator/splitter/PreparedSplitterEnumerator.java
index e0340381..3228d325 100644
--- 
a/flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/core/datastream/source/enumerator/splitter/PreparedSplitterEnumerator.java
+++ 
b/flink-connector-jdbc-core/src/main/java/org/apache/flink/connector/jdbc/core/datastream/source/enumerator/splitter/PreparedSplitterEnumerator.java
@@ -46,13 +46,16 @@ public class PreparedSplitterEnumerator extends 
SqlSplitterEnumerator {
         this.finished = false;
     }
 
+    /** One split per parameter row; an empty matrix gives no split. */
     public static PreparedSplitterEnumerator of(
             String sqlTemplate, Serializable[][] sqlParameters) {
         return new PreparedSplitterEnumerator(sqlTemplate, sqlParameters);
     }
 
+    /** Reads a query without parameters as one split. */
     public static PreparedSplitterEnumerator of(String sqlTemplate) {
-        return new PreparedSplitterEnumerator(sqlTemplate, new 
Serializable[0][]);
+        return new PreparedSplitterEnumerator(
+                sqlTemplate, new Serializable[][] {new Serializable[0]});
     }
 
     public static PreparedSplitterEnumerator of(
diff --git 
a/flink-connector-jdbc-core/src/test/java/org/apache/flink/connector/jdbc/core/datastream/source/JdbcSourceITCase.java
 
b/flink-connector-jdbc-core/src/test/java/org/apache/flink/connector/jdbc/core/datastream/source/JdbcSourceITCase.java
index 0f20a9c8..2bc8bfd2 100644
--- 
a/flink-connector-jdbc-core/src/test/java/org/apache/flink/connector/jdbc/core/datastream/source/JdbcSourceITCase.java
+++ 
b/flink-connector-jdbc-core/src/test/java/org/apache/flink/connector/jdbc/core/datastream/source/JdbcSourceITCase.java
@@ -22,6 +22,7 @@ import 
org.apache.flink.api.common.eventtime.WatermarkStrategy;
 import org.apache.flink.api.common.typeinfo.TypeInformation;
 import org.apache.flink.api.connector.source.Boundedness;
 import org.apache.flink.connector.jdbc.JdbcDataTestBase;
+import 
org.apache.flink.connector.jdbc.core.datastream.source.enumerator.splitter.PreparedSplitterEnumerator;
 import 
org.apache.flink.connector.jdbc.split.JdbcGenericParameterValuesProvider;
 import org.apache.flink.connector.jdbc.testutils.JdbcITCaseBase;
 import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
@@ -159,6 +160,25 @@ class JdbcSourceITCase extends JdbcDataTestBase implements 
JdbcITCaseBase {
     }
 
     /** A sink function to collect the records. */
+    @Test
+    void testReadWithSplitterWithoutParameters() throws Exception {
+        StreamExecutionEnvironment env = 
StreamExecutionEnvironment.getExecutionEnvironment();
+        RestartStrategyUtils.configureNoRestartStrategy(env);
+        env.setParallelism(2);
+        JdbcSource<TestEntry> jdbcSource =
+                JdbcSource.<TestEntry>builder()
+                        
.setTypeInformation(TypeInformation.of(TestEntry.class))
+                        .setSplitter(PreparedSplitterEnumerator.of(sql))
+                        .setDBUrl(getMetadata().getJdbcUrl())
+                        .setDriverName(getMetadata().getDriverClass())
+                        .setResultExtractor(extractor)
+                        .build();
+        env.fromSource(jdbcSource, WatermarkStrategy.noWatermarks(), 
"TestSource")
+                .addSink(new TestingSinkFunction());
+        env.execute();
+        assertThat(collectedRecords).containsExactlyInAnyOrder(TEST_DATA);
+    }
+
     static class TestingSinkFunction implements SinkFunction<TestEntry> {
 
         @Override
diff --git 
a/flink-connector-jdbc-core/src/test/java/org/apache/flink/connector/jdbc/core/datastream/source/enumerator/splitter/PreparedSplitterEnumeratorTest.java
 
b/flink-connector-jdbc-core/src/test/java/org/apache/flink/connector/jdbc/core/datastream/source/enumerator/splitter/PreparedSplitterEnumeratorTest.java
new file mode 100644
index 00000000..606bcd25
--- /dev/null
+++ 
b/flink-connector-jdbc-core/src/test/java/org/apache/flink/connector/jdbc/core/datastream/source/enumerator/splitter/PreparedSplitterEnumeratorTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.flink.connector.jdbc.core.datastream.source.enumerator.splitter;
+
+import org.apache.flink.api.connector.source.Boundedness;
+import 
org.apache.flink.connector.jdbc.core.datastream.source.split.JdbcSourceSplit;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.Serializable;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link PreparedSplitterEnumerator}. */
+class PreparedSplitterEnumeratorTest {
+
+    private static final String QUERY = "select * from books where author = ?";
+    private static final String QUERY_WITHOUT_PARAMETERS = "select * from 
books";
+
+    @Test
+    void testQueryWithoutParametersIsOneSplit() {
+        // the first example in the JdbcSourceBuilder javadoc: a plain query, 
read once
+        PreparedSplitterEnumerator enumerator =
+                PreparedSplitterEnumerator.of("select * from books");
+
+        List<JdbcSourceSplit> splits = enumerator.enumerateSplits();
+
+        assertThat(splits).hasSize(1);
+        assertThat(splits.get(0).getSqlTemplate()).isEqualTo("select * from 
books");
+        assertThat(splits.get(0).getParameters()).isEmpty();
+        assertThat(enumerator.isAllSplitsFinished()).isTrue();
+        assertThat(enumerator.enumerateSplits()).isEmpty();
+    }
+
+    @Test
+    void testOneSplitPerParameterRow() {
+        Serializable[][] parameters = {{"Kumar"}, {"Tan Ah Teck"}};
+
+        List<JdbcSourceSplit> splits =
+                PreparedSplitterEnumerator.of(QUERY, 
parameters).enumerateSplits();
+
+        assertThat(splits).hasSize(2);
+        assertThat(splits.get(0).getParameters()).containsExactly("Kumar");
+        assertThat(splits.get(1).getParameters()).containsExactly("Tan Ah 
Teck");
+        
assertThat(splits.get(0).splitId()).isNotEqualTo(splits.get(1).splitId());
+    }
+
+    @Test
+    void testBoundedAndLineage() {
+        PreparedSplitterEnumerator enumerator =
+                PreparedSplitterEnumerator.of(QUERY_WITHOUT_PARAMETERS);
+
+        assertThat(enumerator.getBoundedness()).isEqualTo(Boundedness.BOUNDED);
+        
assertThat(enumerator.lineageQueries()).containsExactly(QUERY_WITHOUT_PARAMETERS);
+        assertThat(enumerator.serializableState()).isNull();
+    }
+}

Reply via email to