You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/04/11 12:16:15 UTC

[GitHub] [shardingsphere] linghengqian opened a new pull request, #16740: IntervalShardingAlgorithm formats for LocalDateTime

linghengqian opened a new pull request, #16740:
URL: https://github.com/apache/shardingsphere/pull/16740

   Fixes #16738.
   
   Changes proposed in this pull request:
   - IntervalShardingAlgorithm formats for LocalDateTime.
   - Add the corresponding unit tests.
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] linghengqian commented on pull request #16740: IntervalShardingAlgorithm formats for LocalDateTime

Posted by GitBox <gi...@apache.org>.
linghengqian commented on PR #16740:
URL: https://github.com/apache/shardingsphere/pull/16740#issuecomment-1095258548

   This PR was turned off by me until a new ONE came along to fix it.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] zjcnb commented on a diff in pull request #16740: IntervalShardingAlgorithm formats for LocalDateTime

Posted by GitBox <gi...@apache.org>.
zjcnb commented on code in PR #16740:
URL: https://github.com/apache/shardingsphere/pull/16740#discussion_r847347326


##########
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java:
##########
@@ -143,8 +143,20 @@ public String doSharding(final Collection<String> availableTargetNames, final Pr
     }
     
     private boolean hasIntersection(final Range<LocalDateTime> calculateRange, final Range<Comparable<?>> range) {
-        LocalDateTime lower = range.hasLowerBound() ? parseDateTime(range.lowerEndpoint().toString()) : dateTimeLower;
-        LocalDateTime upper = range.hasUpperBound() ? parseDateTime(range.upperEndpoint().toString()) : dateTimeUpper;
+        LocalDateTime lower;
+        if (range.hasLowerBound()) {
+            Comparable<?> lowerEndpoint = range.lowerEndpoint();
+            lower = lowerEndpoint instanceof LocalDateTime ? parseDateTime(((LocalDateTime) lowerEndpoint).format(dateTimeFormatter)) : parseDateTime(lowerEndpoint.toString());
+        } else {
+            lower = dateTimeLower;
+        }
+        LocalDateTime upper;
+        if (range.hasUpperBound()) {
+            Comparable<?> upperEndpoint = range.upperEndpoint();
+            upper = upperEndpoint instanceof LocalDateTime ? parseDateTime(((LocalDateTime) upperEndpoint).format(dateTimeFormatter)) : parseDateTime(upperEndpoint.toString());

Review Comment:
   @linghengqian Thank for your pull request, but i think it should consider `Date` type



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] terrymanu merged pull request #16740: IntervalShardingAlgorithm formats for LocalDateTime and Date

Posted by GitBox <gi...@apache.org>.
terrymanu merged PR #16740:
URL: https://github.com/apache/shardingsphere/pull/16740


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] linghengqian closed pull request #16740: IntervalShardingAlgorithm formats for LocalDateTime

Posted by GitBox <gi...@apache.org>.
linghengqian closed pull request #16740: IntervalShardingAlgorithm formats for LocalDateTime
URL: https://github.com/apache/shardingsphere/pull/16740


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] linghengqian commented on a diff in pull request #16740: IntervalShardingAlgorithm formats for LocalDateTime and Date

Posted by GitBox <gi...@apache.org>.
linghengqian commented on code in PR #16740:
URL: https://github.com/apache/shardingsphere/pull/16740#discussion_r850008155


##########
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java:
##########
@@ -143,8 +143,20 @@ public String doSharding(final Collection<String> availableTargetNames, final Pr
     }
     
     private boolean hasIntersection(final Range<LocalDateTime> calculateRange, final Range<Comparable<?>> range) {
-        LocalDateTime lower = range.hasLowerBound() ? parseDateTime(range.lowerEndpoint().toString()) : dateTimeLower;
-        LocalDateTime upper = range.hasUpperBound() ? parseDateTime(range.upperEndpoint().toString()) : dateTimeUpper;
+        LocalDateTime lower;
+        if (range.hasLowerBound()) {
+            Comparable<?> lowerEndpoint = range.lowerEndpoint();
+            lower = lowerEndpoint instanceof LocalDateTime ? parseDateTime(((LocalDateTime) lowerEndpoint).format(dateTimeFormatter)) : parseDateTime(lowerEndpoint.toString());
+        } else {
+            lower = dateTimeLower;
+        }
+        LocalDateTime upper;
+        if (range.hasUpperBound()) {
+            Comparable<?> upperEndpoint = range.upperEndpoint();
+            upper = upperEndpoint instanceof LocalDateTime ? parseDateTime(((LocalDateTime) upperEndpoint).format(dateTimeFormatter)) : parseDateTime(upperEndpoint.toString());

Review Comment:
   Maybe solved. There doesn't seem to be a `Util` class that lets me use pattern matching like JDK 17.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] linghengqian commented on pull request #16740: IntervalShardingAlgorithm formats for LocalDateTime and Date

Posted by GitBox <gi...@apache.org>.
linghengqian commented on PR #16740:
URL: https://github.com/apache/shardingsphere/pull/16740#issuecomment-1098619604

   It looks like there is something wrong with my IntelliJ IDEA 2022.1, it swallows tabs with blank lines when submitting a commit.🤔


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org