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/05/23 08:03:45 UTC

[GitHub] [shardingsphere] Angry-Rabbit opened a new issue, #17874: IntervalShardingAlgorithm exec sharding fail when sql contain LocalDateTime type column

Angry-Rabbit opened a new issue, #17874:
URL: https://github.com/apache/shardingsphere/issues/17874

   ## Bug Report
   
   
   ### Which version of ShardingSphere did you use?
   
   5.1.1
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   
   ShardingSphere-JDBC
   
   ### Expected behavior
   
   Just a simple query sql with interval sharding algorithm config like below:
   ```
   shardingsphere:
       rules:
         sharding:
           default-database-strategy:
             none:
           default-table-strategy:
             none:
           sharding-algorithms:
             sharding-by-month:
               type: INTERVAL
               props:
                 datetime-pattern: "yyyy-MM-dd HH:mm:ss"
                 datetime-lower: "2022-06-01 00:00:00"
                 datetime-upper: "2022-12-01 00:00:00"
                 sharding-suffix-pattern: "yyyyMM"
                 datetime-interval-amount: 1
                 datetime-interval-unit: "months"
   ```
   
   ```sql
   select id, username from user_info where created_time > '2022-05-01 00:00:00' 
   ```
   
   ### Actual behavior
   
   exec sharding failure, Method threw 'java.time.format.DateTimeParseException' exception. Text '2022-05-22T15:06:54' could not be parsed at index 10
    
   
   ### Reason analyze (If you can)
   
    IntervalShardingAlgorithm#hasIntersection calc range lower and upper endpoint called `range.lowerEndpoint().toString()`,  the output result format will be  "yyyy-MM-dd'T'HH:mm:ss.SSS" that with T char in middle and not match the config props "datetime-pattern: yyyy-MM-dd HH:mm:ss",it cause parseDateTime exec failure.
   
   
   ```
       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;
           BoundType lowerBoundType = range.hasLowerBound() ? range.lowerBoundType() : BoundType.CLOSED;
           BoundType upperBoundType = range.hasUpperBound() ? range.upperBoundType() : BoundType.CLOSED;
           Range<LocalDateTime> dateTimeRange = Range.range(lower, lowerBoundType, upper, upperBoundType);
           return calculateRange.isConnected(dateTimeRange) && !calculateRange.intersection(dateTimeRange).isEmpty();
       }
       
       private LocalDateTime parseDateTime(final String value) {
           return **LocalDateTime.parse(value.substring(0, dateTimePatternLength), dateTimeFormatter);**
       }
   
   ```
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
   
   none
   
   ### Example codes for reproduce this issue (such as a github link).
   none


-- 
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.apache.org

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


[GitHub] [shardingsphere] linghengqian commented on issue #17874: IntervalShardingAlgorithm exec sharding fail when sql contain LocalDateTime type column

Posted by GitBox <gi...@apache.org>.
linghengqian commented on issue #17874:
URL: https://github.com/apache/shardingsphere/issues/17874#issuecomment-1134345826

   - Duplicated with https://github.com/apache/shardingsphere/pull/16740 , already implemented in the master branch, this issue should be closed. 
   
   - You can port the master branch's algorithm down to 5.1.1 by `CLASS_BASE` custom sharding algorithm.


-- 
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] Angry-Rabbit closed issue #17874: IntervalShardingAlgorithm exec sharding fail when sql contain LocalDateTime type column

Posted by GitBox <gi...@apache.org>.
Angry-Rabbit closed issue #17874: IntervalShardingAlgorithm exec sharding fail when sql contain LocalDateTime type column
URL: https://github.com/apache/shardingsphere/issues/17874


-- 
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