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

zhonghongsheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new eca2815b67c Refactor IntegerPrimaryKeyIngestPosition to support null 
value (#37502)
eca2815b67c is described below

commit eca2815b67c0c19c67ce354ab7f34d1482b4df5f
Author: Hongsheng Zhong <[email protected]>
AuthorDate: Thu Dec 25 13:20:41 2025 +0800

    Refactor IntegerPrimaryKeyIngestPosition to support null value (#37502)
---
 .../type/pk/PrimaryKeyIngestPositionFactory.java         |  3 ++-
 .../type/pk/type/IntegerPrimaryKeyIngestPosition.java    |  8 ++++----
 .../calculator/InventoryPositionCalculator.java          |  2 +-
 .../type/pk/PrimaryKeyIngestPositionFactoryTest.java     | 16 ++++++++++++----
 .../pk/type/IntegerPrimaryKeyIngestPositionTest.java     |  7 +++++++
 .../context/ConsistencyCheckJobItemContextTest.java      | 12 ++++++------
 6 files changed, 32 insertions(+), 16 deletions(-)

diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/PrimaryKeyIngestPositionFactory.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/PrimaryKeyIngestPositionFactory.java
index 76bf0c16a57..da57e51d894 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/PrimaryKeyIngestPositionFactory.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/PrimaryKeyIngestPositionFactory.java
@@ -19,6 +19,7 @@ package 
org.apache.shardingsphere.data.pipeline.core.ingest.position.type.pk;
 
 import com.google.common.base.Preconditions;
 import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import 
org.apache.shardingsphere.data.pipeline.core.ingest.position.type.pk.type.IntegerPrimaryKeyIngestPosition;
@@ -49,7 +50,7 @@ public final class PrimaryKeyIngestPositionFactory {
         String endValue = parts.get(2);
         switch (type) {
             case 'i':
-                return new 
IntegerPrimaryKeyIngestPosition(Long.parseLong(beginValue), 
Long.parseLong(endValue));
+                return new 
IntegerPrimaryKeyIngestPosition(Strings.isNullOrEmpty(beginValue) ? null : 
Long.parseLong(beginValue), Strings.isNullOrEmpty(endValue) ? null : 
Long.parseLong(endValue));
             case 's':
                 return new StringPrimaryKeyIngestPosition(beginValue, 
endValue);
             case 'u':
diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/type/IntegerPrimaryKeyIngestPosition.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/type/IntegerPrimaryKeyIngestPosition.java
index f235759e42c..cdbd21e37c7 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/type/IntegerPrimaryKeyIngestPosition.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/type/IntegerPrimaryKeyIngestPosition.java
@@ -24,11 +24,11 @@ import 
org.apache.shardingsphere.data.pipeline.core.ingest.position.type.pk.Prim
  */
 public final class IntegerPrimaryKeyIngestPosition implements 
PrimaryKeyIngestPosition<Long> {
     
-    private final long beginValue;
+    private final Long beginValue;
     
-    private final long endValue;
+    private final Long endValue;
     
-    public IntegerPrimaryKeyIngestPosition(final long beginValue, final long 
endValue) {
+    public IntegerPrimaryKeyIngestPosition(final Long beginValue, final Long 
endValue) {
         this.beginValue = beginValue;
         this.endValue = endValue;
     }
@@ -50,6 +50,6 @@ public final class IntegerPrimaryKeyIngestPosition implements 
PrimaryKeyIngestPo
     
     @Override
     public String toString() {
-        return String.format("%s,%s,%s", getType(), beginValue, endValue);
+        return String.format("%s,%s,%s", getType(), null == beginValue ? "" : 
beginValue, null == endValue ? "" : endValue);
     }
 }
diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/calculator/InventoryPositionCalculator.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/calculator/InventoryPositionCalculator.java
index 11cea24cb28..4f95a43de67 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/calculator/InventoryPositionCalculator.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/calculator/InventoryPositionCalculator.java
@@ -45,7 +45,7 @@ public final class InventoryPositionCalculator {
      */
     public static List<IngestPosition> 
getPositionByIntegerUniqueKeyRange(final long tableRecordsCount, final 
Range<Long> uniqueKeyValuesRange, final long shardingSize) {
         if (0 == tableRecordsCount) {
-            return Collections.singletonList(new 
IntegerPrimaryKeyIngestPosition(0, 0));
+            return Collections.singletonList(new 
IntegerPrimaryKeyIngestPosition(0L, 0L));
         }
         List<IngestPosition> result = new LinkedList<>();
         long splitCount = tableRecordsCount / shardingSize + 
(tableRecordsCount % shardingSize > 0 ? 1 : 0);
diff --git 
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/PrimaryKeyIngestPositionFactoryTest.java
 
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/PrimaryKeyIngestPositionFactoryTest.java
index 3496c4a2664..c8b310a38bf 100644
--- 
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/PrimaryKeyIngestPositionFactoryTest.java
+++ 
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/PrimaryKeyIngestPositionFactoryTest.java
@@ -24,6 +24,7 @@ import org.junit.jupiter.api.Test;
 
 import java.util.Collections;
 
+import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertNull;
@@ -33,10 +34,17 @@ class PrimaryKeyIngestPositionFactoryTest {
     
     @Test
     void assertNewInstanceWithIntegerPrimaryKeyIngestPosition() {
-        IntegerPrimaryKeyIngestPosition actual = 
(IntegerPrimaryKeyIngestPosition) 
PrimaryKeyIngestPositionFactory.newInstance("i,100,200");
-        assertThat(actual.getType(), is('i'));
-        assertThat(actual.getBeginValue(), is(100L));
-        assertThat(actual.getEndValue(), is(200L));
+        
assertIntegerPrimaryKeyIngestPosition0(PrimaryKeyIngestPositionFactory.newInstance("i,100,200"),
 new IntegerPrimaryKeyIngestPosition(100L, 200L));
+        
assertIntegerPrimaryKeyIngestPosition0(PrimaryKeyIngestPositionFactory.newInstance("i,100,"),
 new IntegerPrimaryKeyIngestPosition(100L, null));
+        
assertIntegerPrimaryKeyIngestPosition0(PrimaryKeyIngestPositionFactory.newInstance("i,,200"),
 new IntegerPrimaryKeyIngestPosition(null, 200L));
+        
assertIntegerPrimaryKeyIngestPosition0(PrimaryKeyIngestPositionFactory.newInstance("i,,"),
 new IntegerPrimaryKeyIngestPosition(null, null));
+    }
+    
+    private void assertIntegerPrimaryKeyIngestPosition0(final 
PrimaryKeyIngestPosition<?> actual, final IntegerPrimaryKeyIngestPosition 
expected) {
+        assertThat(actual, instanceOf(IntegerPrimaryKeyIngestPosition.class));
+        assertThat(actual.getType(), is(expected.getType()));
+        assertThat(actual.getBeginValue(), is(expected.getBeginValue()));
+        assertThat(actual.getEndValue(), is(expected.getEndValue()));
     }
     
     @Test
diff --git 
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/type/IntegerPrimaryKeyIngestPositionTest.java
 
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/type/IntegerPrimaryKeyIngestPositionTest.java
index a1896b319d5..e5e79c14979 100644
--- 
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/type/IntegerPrimaryKeyIngestPositionTest.java
+++ 
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/position/type/pk/type/IntegerPrimaryKeyIngestPositionTest.java
@@ -28,4 +28,11 @@ class IntegerPrimaryKeyIngestPositionTest {
     void assertToString() {
         assertThat(new IntegerPrimaryKeyIngestPosition(1L, 100L).toString(), 
is("i,1,100"));
     }
+    
+    @Test
+    void assertToStringWithNullValue() {
+        assertThat(new IntegerPrimaryKeyIngestPosition(1L, null).toString(), 
is("i,1,"));
+        assertThat(new IntegerPrimaryKeyIngestPosition(null, 100L).toString(), 
is("i,,100"));
+        assertThat(new IntegerPrimaryKeyIngestPosition(null, null).toString(), 
is("i,,"));
+    }
 }
diff --git 
a/kernel/data-pipeline/scenario/consistency-check/src/test/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckJobItemContextTest.java
 
b/kernel/data-pipeline/scenario/consistency-check/src/test/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckJobItemContextTest.java
index aae4d9512b8..388d7560d56 100644
--- 
a/kernel/data-pipeline/scenario/consistency-check/src/test/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckJobItemContextTest.java
+++ 
b/kernel/data-pipeline/scenario/consistency-check/src/test/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckJobItemContextTest.java
@@ -50,17 +50,17 @@ class ConsistencyCheckJobItemContextTest {
     @Test
     void assertConstructWithNonEmptyValues() {
         ConsistencyCheckJobItemProgress jobItemProgress = new 
ConsistencyCheckJobItemProgress(TABLE, null, 0L, 10L, null, null, "H2");
-        jobItemProgress.getTableCheckRangePositions().add(new 
TableCheckRangePosition(0, DATA_NODE, TABLE, new 
IntegerPrimaryKeyIngestPosition(1, 100),
-                new IntegerPrimaryKeyIngestPosition(1, 101), null, 11, 11, 
false, null));
-        jobItemProgress.getTableCheckRangePositions().add(new 
TableCheckRangePosition(1, DATA_NODE, TABLE, new 
IntegerPrimaryKeyIngestPosition(101, 200),
-                new IntegerPrimaryKeyIngestPosition(101, 203), null, 132, 132, 
false, null));
+        jobItemProgress.getTableCheckRangePositions().add(new 
TableCheckRangePosition(0, DATA_NODE, TABLE, new 
IntegerPrimaryKeyIngestPosition(1L, 100L),
+                new IntegerPrimaryKeyIngestPosition(1L, 101L), null, 11, 11, 
false, null));
+        jobItemProgress.getTableCheckRangePositions().add(new 
TableCheckRangePosition(1, DATA_NODE, TABLE, new 
IntegerPrimaryKeyIngestPosition(101L, 200L),
+                new IntegerPrimaryKeyIngestPosition(101L, 203L), null, 132, 
132, false, null));
         ConsistencyCheckJobItemContext actual = new 
ConsistencyCheckJobItemContext(new ConsistencyCheckJobConfiguration("", "", 
"DATA_MATCH", null, databaseType),
                 0, JobStatus.RUNNING, jobItemProgress);
         
assertThat(actual.getProgressContext().getTableCheckRangePositions().size(), 
is(2));
         
assertTableCheckRangePosition(actual.getProgressContext().getTableCheckRangePositions().get(0),
-                new TableCheckRangePosition(0, DATA_NODE, TABLE, new 
IntegerPrimaryKeyIngestPosition(1, 100), new IntegerPrimaryKeyIngestPosition(1, 
101), null, 11, 11, false, null));
+                new TableCheckRangePosition(0, DATA_NODE, TABLE, new 
IntegerPrimaryKeyIngestPosition(1L, 100L), new 
IntegerPrimaryKeyIngestPosition(1L, 101L), null, 11, 11, false, null));
         
assertTableCheckRangePosition(actual.getProgressContext().getTableCheckRangePositions().get(1),
-                new TableCheckRangePosition(1, DATA_NODE, TABLE, new 
IntegerPrimaryKeyIngestPosition(101, 200), new 
IntegerPrimaryKeyIngestPosition(101, 203), null, 132, 132, false, null));
+                new TableCheckRangePosition(1, DATA_NODE, TABLE, new 
IntegerPrimaryKeyIngestPosition(101L, 200L), new 
IntegerPrimaryKeyIngestPosition(101L, 203L), null, 132, 132, false, null));
     }
     
     private void assertTableCheckRangePosition(final TableCheckRangePosition 
actual, final TableCheckRangePosition expected) {

Reply via email to