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:
[email protected]
For queries about this service, please contact Infrastructure at:
[email protected]