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 2c613196d37 Rename IntervalToRangeIterator to 
IntegerRangeSplittingIterator and refactor (#37545)
2c613196d37 is described below

commit 2c613196d3708e966f3eb4274a18cbcd16260648
Author: Hongsheng Zhong <[email protected]>
AuthorDate: Fri Dec 26 21:32:14 2025 +0800

    Rename IntervalToRangeIterator to IntegerRangeSplittingIterator and 
refactor (#37545)
    
    * Move IntervalToRangeIterator to query pkg
    
    * Rename IntervalToRangeIterator to IntegerRangeSplittingIterator
    
    * Rename IntegerRangeSplittingIterator fields
    
    * Replace commons-lang3 Range
---
 .../query/IntegerRangeSplittingIterator.java}      | 31 ++++++++++------------
 .../InventoryPositionEstimatedCalculator.java      | 10 +++----
 .../query/IntegerRangeSplittingIteratorTest.java}  | 27 +++++++++----------
 3 files changed, 32 insertions(+), 36 deletions(-)

diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/IntervalToRangeIterator.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/dumper/inventory/query/IntegerRangeSplittingIterator.java
similarity index 64%
rename from 
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/IntervalToRangeIterator.java
rename to 
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/dumper/inventory/query/IntegerRangeSplittingIterator.java
index 694fe0fa4fd..ce21597e988 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/IntervalToRangeIterator.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/ingest/dumper/inventory/query/IntegerRangeSplittingIterator.java
@@ -15,37 +15,34 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.data.pipeline.core.util;
-
-import org.apache.commons.lang3.Range;
+package 
org.apache.shardingsphere.data.pipeline.core.ingest.dumper.inventory.query;
 
 import java.math.BigInteger;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 
 /**
- * Interval to range iterator.
- * <p>
- * It's not thread-safe.
- * </p>
+ * Integer range splitting iterator.
+ *
+ * <p>It's not thread-safe.</p>
  */
-public final class IntervalToRangeIterator implements Iterator<Range<Long>> {
+public final class IntegerRangeSplittingIterator implements 
Iterator<Range<Long>> {
     
     private final BigInteger maximum;
     
-    private final BigInteger interval;
+    private final BigInteger stepSize;
     
     private BigInteger current;
     
-    public IntervalToRangeIterator(final long minimum, final long maximum, 
final long interval) {
+    public IntegerRangeSplittingIterator(final long minimum, final long 
maximum, final long stepSize) {
         if (minimum > maximum) {
             throw new IllegalArgumentException("minimum greater than maximum");
         }
-        if (interval < 0L) {
-            throw new IllegalArgumentException("interval is less than zero");
+        if (stepSize < 0L) {
+            throw new IllegalArgumentException("step size is less than zero");
         }
         this.maximum = BigInteger.valueOf(maximum);
-        this.interval = BigInteger.valueOf(interval);
+        this.stepSize = BigInteger.valueOf(stepSize);
         current = BigInteger.valueOf(minimum);
     }
     
@@ -59,13 +56,13 @@ public final class IntervalToRangeIterator implements 
Iterator<Range<Long>> {
         if (!hasNext()) {
             throw new NoSuchElementException("");
         }
-        BigInteger upperLimit = min(maximum, current.add(interval));
-        Range<Long> result = Range.of(current.longValue(), 
upperLimit.longValue());
+        BigInteger upperLimit = min(maximum, current.add(stepSize));
+        Range<Long> result = Range.closed(current.longValue(), 
upperLimit.longValue());
         current = upperLimit.add(BigInteger.ONE);
         return result;
     }
     
-    private BigInteger min(final BigInteger integer1, final BigInteger 
integer2) {
-        return integer1.compareTo(integer2) < 0 ? integer1 : integer2;
+    private BigInteger min(final BigInteger one, final BigInteger another) {
+        return one.compareTo(another) < 0 ? one : another;
     }
 }
diff --git 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/calculator/position/estimated/InventoryPositionEstimatedCalculator.java
 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/calculator/position/estimated/InventoryPositionEstimatedCalculator.java
index 924272fa9b7..d6f19017173 100644
--- 
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/calculator/position/estimated/InventoryPositionEstimatedCalculator.java
+++ 
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/preparer/inventory/calculator/position/estimated/InventoryPositionEstimatedCalculator.java
@@ -21,11 +21,11 @@ import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import 
org.apache.shardingsphere.data.pipeline.core.datasource.PipelineDataSource;
 import 
org.apache.shardingsphere.data.pipeline.core.exception.job.SplitPipelineJobByUniqueKeyException;
+import 
org.apache.shardingsphere.data.pipeline.core.ingest.dumper.inventory.query.IntegerRangeSplittingIterator;
 import 
org.apache.shardingsphere.data.pipeline.core.ingest.dumper.inventory.query.Range;
 import 
org.apache.shardingsphere.data.pipeline.core.ingest.position.IngestPosition;
 import 
org.apache.shardingsphere.data.pipeline.core.ingest.position.type.pk.type.IntegerPrimaryKeyIngestPosition;
 import 
org.apache.shardingsphere.data.pipeline.core.sqlbuilder.sql.PipelinePrepareSQLBuilder;
-import 
org.apache.shardingsphere.data.pipeline.core.util.IntervalToRangeIterator;
 import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedTable;
 
 import java.math.BigInteger;
@@ -82,11 +82,11 @@ public final class InventoryPositionEstimatedCalculator {
         }
         List<IngestPosition> result = new LinkedList<>();
         long splitCount = tableRecordsCount / shardingSize + 
(tableRecordsCount % shardingSize > 0 ? 1 : 0);
-        long interval = 
BigInteger.valueOf(maximum).subtract(BigInteger.valueOf(minimum)).divide(BigInteger.valueOf(splitCount)).longValue();
-        IntervalToRangeIterator rangeIterator = new 
IntervalToRangeIterator(minimum, maximum, interval);
+        long stepSize = 
BigInteger.valueOf(maximum).subtract(BigInteger.valueOf(minimum)).divide(BigInteger.valueOf(splitCount)).longValue();
+        IntegerRangeSplittingIterator rangeIterator = new 
IntegerRangeSplittingIterator(minimum, maximum, stepSize);
         while (rangeIterator.hasNext()) {
-            org.apache.commons.lang3.Range<Long> range = rangeIterator.next();
-            result.add(new IntegerPrimaryKeyIngestPosition(range.getMinimum(), 
range.getMaximum()));
+            Range<Long> range = rangeIterator.next();
+            result.add(new 
IntegerPrimaryKeyIngestPosition(range.getLowerBound(), range.getUpperBound()));
         }
         return result;
     }
diff --git 
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/IntervalToRangeIteratorTest.java
 
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/dumper/inventory/query/IntegerRangeSplittingIteratorTest.java
similarity index 69%
rename from 
kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/IntervalToRangeIteratorTest.java
rename to 
kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/dumper/inventory/query/IntegerRangeSplittingIteratorTest.java
index ab8fe008bde..cdf44899b8c 100644
--- 
a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/IntervalToRangeIteratorTest.java
+++ 
b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/ingest/dumper/inventory/query/IntegerRangeSplittingIteratorTest.java
@@ -15,9 +15,8 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.data.pipeline.core.util;
+package 
org.apache.shardingsphere.data.pipeline.core.ingest.dumper.inventory.query;
 
-import org.apache.commons.lang3.Range;
 import org.junit.jupiter.api.Test;
 
 import java.util.LinkedList;
@@ -28,21 +27,21 @@ import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
-class IntervalToRangeIteratorTest {
+class IntegerRangeSplittingIteratorTest {
     
     @Test
     void assertMinimumGreaterThanMaximum() {
-        assertThrows(IllegalArgumentException.class, () -> new 
IntervalToRangeIterator(200L, 100L, 10L));
+        assertThrows(IllegalArgumentException.class, () -> new 
IntegerRangeSplittingIterator(200L, 100L, 10L));
     }
     
     @Test
     void assertIntervalLessThanZero() {
-        assertThrows(IllegalArgumentException.class, () -> new 
IntervalToRangeIterator(100L, 200L, -10L));
+        assertThrows(IllegalArgumentException.class, () -> new 
IntegerRangeSplittingIterator(100L, 200L, -10L));
     }
     
     @Test
     void assertInvalidNext() {
-        IntervalToRangeIterator iterator = new IntervalToRangeIterator(200L, 
200L, 0L);
+        IntegerRangeSplittingIterator iterator = new 
IntegerRangeSplittingIterator(200L, 200L, 0L);
         if (iterator.hasNext()) {
             iterator.next();
         }
@@ -51,27 +50,27 @@ class IntervalToRangeIteratorTest {
     
     @Test
     void assertSmallRangeCorrect() {
-        IntervalToRangeIterator iterator = new IntervalToRangeIterator(200L, 
200L, 0L);
+        IntegerRangeSplittingIterator iterator = new 
IntegerRangeSplittingIterator(200L, 200L, 0L);
         List<Range<Long>> actual = new LinkedList<>();
         while (iterator.hasNext()) {
             actual.add(iterator.next());
         }
         assertThat(actual.size(), is(1));
-        assertThat(actual.get(0).getMinimum(), is(200L));
-        assertThat(actual.get(0).getMaximum(), is(200L));
+        assertThat(actual.get(0).getLowerBound(), is(200L));
+        assertThat(actual.get(0).getUpperBound(), is(200L));
     }
     
     @Test
     void assertLargeRangeCorrect() {
-        IntervalToRangeIterator iterator = new IntervalToRangeIterator(200L, 
400L, 100L);
+        IntegerRangeSplittingIterator iterator = new 
IntegerRangeSplittingIterator(200L, 400L, 100L);
         List<Range<Long>> actual = new LinkedList<>();
         while (iterator.hasNext()) {
             actual.add(iterator.next());
         }
         assertThat(actual.size(), is(2));
-        assertThat(actual.get(0).getMinimum(), is(200L));
-        assertThat(actual.get(0).getMaximum(), is(300L));
-        assertThat(actual.get(1).getMinimum(), is(301L));
-        assertThat(actual.get(1).getMaximum(), is(400L));
+        assertThat(actual.get(0).getLowerBound(), is(200L));
+        assertThat(actual.get(0).getUpperBound(), is(300L));
+        assertThat(actual.get(1).getLowerBound(), is(301L));
+        assertThat(actual.get(1).getUpperBound(), is(400L));
     }
 }

Reply via email to