> entry : partitionRangeMap.entrySet()) {
if (entry.getValue().contains(value)) {
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/strategy/algorithm/sharding/range/StandardRangeShardingAlgorithm.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/strategy/algorithm/sharding/range/StandardRangeShardingAlgorithm.java
index c8a457bc474f10e53413cc06391db5bad0277602..89cab338cfbe932a6fc29463e447dc93c091a09d 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/strategy/algorithm/sharding/range/StandardRangeShardingAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/strategy/algorithm/sharding/range/StandardRangeShardingAlgorithm.java
@@ -31,20 +31,20 @@ import java.util.Properties;
*
*
* Standard range sharding algorithm is similar to the rule of partition table, but it can only be split by the same size.
- * User can specify the range by setting `partition.lower`, `partition.upper` and `partition.volume` parameters.
+ * User can specify the range by setting `range.lower`, `range.upper` and `partition.volume` parameters.
* The `partition.volume` parameter determines the size of each partition.
*
*
- * For example: If the `partition.lower` parameter is set to `10`, the `partition.upper` parameter is set to `45`,
+ * For example: If the `range.lower` parameter is set to `10`, the `range.upper` parameter is set to `45`,
* and the `partition.volume` parameter is set to `10`. The values in range [10,45] will be split to different partitions
* ——[10,20), [20, 30), [30, 40), [40, 45), and other values will be split to (-∞, 10) and [45, +∞).
*
*/
public final class StandardRangeShardingAlgorithm extends AbstractRangeShardingAlgorithm {
- private static final String PARTITION_LOWER = "partition.lower";
+ private static final String RANGE_LOWER = "range.lower";
- private static final String PARTITION_UPPER = "partition.upper";
+ private static final String RANGE_UPPER = "range.upper";
private static final String PARTITION_VOLUME = "partition.volume";
@@ -55,11 +55,11 @@ public final class StandardRangeShardingAlgorithm extends AbstractRangeShardingA
@Override
public Map> createPartitionRangeMap(final Properties properties) {
- Preconditions.checkNotNull(properties.get(PARTITION_LOWER), "Standard range sharding algorithm partition lower cannot be null.");
- Preconditions.checkNotNull(properties.get(PARTITION_UPPER), "Standard range sharding algorithm partition upper cannot be null.");
+ Preconditions.checkNotNull(properties.get(RANGE_LOWER), "Standard range sharding algorithm partition lower cannot be null.");
+ Preconditions.checkNotNull(properties.get(RANGE_UPPER), "Standard range sharding algorithm partition upper cannot be null.");
Preconditions.checkNotNull(properties.get(PARTITION_VOLUME), "Standard range sharding algorithm partition volume cannot be null.");
- long lower = Long.parseLong(properties.get(PARTITION_LOWER).toString());
- long upper = Long.parseLong(properties.get(PARTITION_UPPER).toString());
+ long lower = Long.parseLong(properties.get(RANGE_LOWER).toString());
+ long upper = Long.parseLong(properties.get(RANGE_UPPER).toString());
long volume = Long.parseLong(properties.get(PARTITION_VOLUME).toString());
Preconditions.checkArgument(upper - lower >= volume, "Standard range sharding algorithm partition range can not be smaller than volume.");
int partitionSize = Math.toIntExact(LongMath.divide(upper - lower, volume, RoundingMode.CEILING));
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/strategy/algorithm/sharding/DatetimeShardingAlgorithmTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/strategy/algorithm/sharding/DatetimeShardingAlgorithmTest.java
index 1eb4b45460e73a045a9bf112b7de1130d2bebadc..73925f3f40aaa02990583ca6d393b88421240005 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/strategy/algorithm/sharding/DatetimeShardingAlgorithmTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/strategy/algorithm/sharding/DatetimeShardingAlgorithmTest.java
@@ -104,7 +104,7 @@ public final class DatetimeShardingAlgorithmTest {
}
@Test
- public void assertPreciseDoShardingWithoutLowerBound() {
+ public void assertRangeDoShardingWithoutLowerBound() {
List availableTargetNames = Lists.newArrayList("t_order_0", "t_order_1", "t_order_2", "t_order_3");
Range rangeValue = Range.lessThan("2020-01-01 00:00:11");
List shardingValues = Lists.newArrayList(new RangeRouteValue<>("create_time", "t_order", rangeValue));
@@ -117,7 +117,7 @@ public final class DatetimeShardingAlgorithmTest {
}
@Test
- public void assertPreciseDoShardingWithoutUpperBound() {
+ public void assertRangeDoShardingWithoutUpperBound() {
List availableTargetNames = Lists.newArrayList("t_order_0", "t_order_1", "t_order_2", "t_order_3", "t_order_4", "t_order_5");
Range rangeValue = Range.greaterThan("2020-01-01 00:00:09");
List shardingValues = Lists.newArrayList(new RangeRouteValue<>("create_time", "t_order", rangeValue));
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/strategy/algorithm/sharding/range/StandardRangeShardingAlgorithmTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/strategy/algorithm/sharding/range/StandardRangeShardingAlgorithmTest.java
index 089709708fa0cd1c49beb0817a82a80f77b4c530..a62d682b8a8735a38eceb516fe7084e07fdec97f 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/strategy/algorithm/sharding/range/StandardRangeShardingAlgorithmTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/strategy/algorithm/sharding/range/StandardRangeShardingAlgorithmTest.java
@@ -43,8 +43,8 @@ public final class StandardRangeShardingAlgorithmTest {
@Before
public void setUp() {
StandardRangeShardingAlgorithm shardingAlgorithm = new StandardRangeShardingAlgorithm();
- shardingAlgorithm.getProperties().setProperty("partition.lower", "10");
- shardingAlgorithm.getProperties().setProperty("partition.upper", "45");
+ shardingAlgorithm.getProperties().setProperty("range.lower", "10");
+ shardingAlgorithm.getProperties().setProperty("range.upper", "45");
shardingAlgorithm.getProperties().setProperty("partition.volume", "10");
shardingAlgorithm.init();
StandardShardingStrategyConfiguration shardingStrategyConfig = new StandardShardingStrategyConfiguration("order_id", shardingAlgorithm);
@@ -62,6 +62,26 @@ public final class StandardRangeShardingAlgorithmTest {
assertTrue(actual.contains("t_order_2"));
assertTrue(actual.contains("t_order_5"));
}
+
+ @Test
+ public void assertRangeDoShardingWithoutLowerBound() {
+ List availableTargetNames = Lists.newArrayList("t_order_0", "t_order_1", "t_order_2", "t_order_3", "t_order_4", "t_order_5");
+ List shardingValues = Lists.newArrayList(new RangeRouteValue<>("order_id", "t_order", Range.lessThan(12L)));
+ Collection actual = shardingStrategy.doSharding(availableTargetNames, shardingValues, new ConfigurationProperties(new Properties()));
+ assertThat(actual.size(), is(2));
+ assertTrue(actual.contains("t_order_0"));
+ assertTrue(actual.contains("t_order_1"));
+ }
+
+ @Test
+ public void assertRangeDoShardingWithoutUpperBound() {
+ List availableTargetNames = Lists.newArrayList("t_order_0", "t_order_1", "t_order_2", "t_order_3", "t_order_4", "t_order_5");
+ List shardingValues = Lists.newArrayList(new RangeRouteValue<>("order_id", "t_order", Range.greaterThan(40L)));
+ Collection actual = shardingStrategy.doSharding(availableTargetNames, shardingValues, new ConfigurationProperties(new Properties()));
+ assertThat(actual.size(), is(2));
+ assertTrue(actual.contains("t_order_4"));
+ assertTrue(actual.contains("t_order_5"));
+ }
@Test
public void assertRangeDoSharding() {
@@ -79,8 +99,8 @@ public final class StandardRangeShardingAlgorithmTest {
@Test
public void assertGetAutoTablesAmount() {
StandardRangeShardingAlgorithm shardingAlgorithm = new StandardRangeShardingAlgorithm();
- shardingAlgorithm.getProperties().setProperty("partition.lower", "10");
- shardingAlgorithm.getProperties().setProperty("partition.upper", "45");
+ shardingAlgorithm.getProperties().setProperty("range.lower", "10");
+ shardingAlgorithm.getProperties().setProperty("range.upper", "45");
shardingAlgorithm.getProperties().setProperty("partition.volume", "10");
shardingAlgorithm.init();
assertThat(shardingAlgorithm.getAutoTablesAmount(), is(6));