strongduanmu commented on a change in pull request #12625:
URL: https://github.com/apache/shardingsphere/pull/12625#discussion_r714421917



##########
File path: 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
##########
@@ -135,10 +151,12 @@ public String doSharding(final Collection<String> 
availableTargetNames, final Pr
         }
         LocalDateTime startTime = hasStartTime ? 
parseDateTime(shardingValue.getValueRange().lowerEndpoint().toString()) : 
dateTimeLower;
         LocalDateTime endTime = hasEndTime ? 
parseDateTime(shardingValue.getValueRange().upperEndpoint().toString()) : 
dateTimeUpper;
-        LocalDateTime calculateTime = startTime;
+        LocalDateTime calculateTime = dateTimeLower;
         Set<String> result = new HashSet<>();
-        while (!calculateTime.isAfter(endTime) || 
calculateTime.format(tableSuffixPattern).equals(endTime.format(tableSuffixPattern)))
 {
-            result.addAll(getMatchedTables(calculateTime, 
availableTargetNames));
+        while (!calculateTime.isAfter(dateTimeUpper)) {
+            if (calculateTime.plus(stepAmount, stepUnit).isAfter(startTime) && 
!calculateTime.isAfter(endTime)) {

Review comment:
       @tuichenchuxin Can we extract this common logic?

##########
File path: 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java
##########
@@ -120,10 +121,25 @@ private ChronoUnit getStepUnit(final String stepUnit) {
     
     @Override
     public String doSharding(final Collection<String> availableTargetNames, 
final PreciseShardingValue<Comparable<?>> shardingValue) {
-        String tableNameSuffix = 
parseDateTime(shardingValue.getValue().toString()).format(tableSuffixPattern);
-        return availableTargetNames.stream()
-                .filter(each -> each.endsWith(tableNameSuffix))
-                .findFirst().orElse(null);
+        return doSharding(shardingValue).flatMap(suffix -> 
availableTargetNames.stream()
+                .filter(each -> each.endsWith(suffix))
+                .findFirst()).orElse(null);
+    }
+    
+    private Optional<String> doSharding(final 
PreciseShardingValue<Comparable<?>> shardingValue) {
+        LocalDateTime dateTime = 
parseDateTime(shardingValue.getValue().toString());
+        if (dateTime.isBefore(dateTimeLower) || 
!dateTime.isBefore(dateTimeUpper)) {

Review comment:
       @tuichenchuxin `isAfter` may be better.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to