singlemonkey opened a new issue #8722:
URL: https://github.com/apache/shardingsphere/issues/8722


   ## Bug Report
   
   When using the localdatetime type as the partition key, the data will be 
changed to "yyyy-MM-ddTHH:mm:ss" after toString method,and then cannot parse to 
LocalDateTime with the defined "datetime-pattern" is "yyyy-MM-dd HH:mm:ss".Get 
error log like this:
   ```
   Caused by: java.time.format.DateTimeParseException: Text 
'1992-08-02T08:30:11' could not be parsed at index 10
        at 
java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949)
        at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
        at java.time.LocalDateTime.parse(LocalDateTime.java:492)
        at 
org.apache.shardingsphere.sharding.algorithm.sharding.datetime.IntervalShardingAlgorithm.parseDateTime(IntervalShardingAlgorithm.java:149)
        at 
org.apache.shardingsphere.sharding.algorithm.sharding.datetime.IntervalShardingAlgorithm.doSharding(IntervalShardingAlgorithm.java:136)
        at 
org.apache.shardingsphere.sharding.route.strategy.type.standard.StandardShardingStrategy.doSharding(StandardShardingStrategy.java:77)
        at 
org.apache.shardingsphere.sharding.route.strategy.type.standard.StandardShardingStrategy.doSharding(StandardShardingStrategy.java:56)
        at 
org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeTables(ShardingStandardRoutingEngine.java:214)
        at 
org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.route0(ShardingStandardRoutingEngine.java:194)
        at 
org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeByShardingConditionsWithCondition(ShardingStandardRoutingEngine.java:114)
        at 
org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeByShardingConditions(ShardingStandardRoutingEngine.java:107)
        at 
org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.getDataNodes(ShardingStandardRoutingEngine.java:84)
        at 
org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.route(ShardingStandardRoutingEngine.java:69)
        at 
org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.createRouteContext(ShardingSQLRouter.java:70)
        at 
org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.createRouteContext(ShardingSQLRouter.java:55)
        at 
org.apache.shardingsphere.infra.route.engine.impl.PartialSQLRouteExecutor.route(PartialSQLRouteExecutor.java:59)
        at 
org.apache.shardingsphere.infra.route.engine.SQLRouteEngine.route(SQLRouteEngine.java:57)
        at 
org.apache.shardingsphere.infra.context.kernel.KernelProcessor.generateExecutionContext(KernelProcessor.java:52)
        at 
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.createExecutionContext(ShardingSpherePreparedStatement.java:266)
        at 
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.execute(ShardingSpherePreparedStatement.java:198)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at 
org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59)
        at com.sun.proxy.$Proxy79.execute(Unknown Source)
        at 
org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:64)
        at 
org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)
        at 
com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doQuery(MybatisSimpleExecutor.java:69)
        at 
org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325)
        at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
        at 
com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.query(MybatisCachingExecutor.java:165)
        at 
com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.query(MybatisCachingExecutor.java:92)
        at 
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
   ```
   
   ### Which version of ShardingSphere did you use?
   5.0.0
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
    ShardingSphere-JDBC
   
   ### parse code like this:
   
   ```
   
/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.class
   ```
   
   ```
   public Collection<String> doSharding(Collection<String> 
availableTargetNames, RangeShardingValue<Comparable<?>> shardingValue) {
     boolean hasStartTime = shardingValue.getValueRange().hasLowerBound();
     boolean hasEndTime = shardingValue.getValueRange().hasUpperBound();
     if (!hasStartTime && !hasEndTime) {
         return availableTargetNames;
     } else {
         LocalDateTime startTime = hasStartTime ? 
this.parseDateTime(shardingValue.getValueRange().lowerEndpoint().toString()) : 
this.dateTimeLower;
         LocalDateTime endTime = hasEndTime ? 
this.parseDateTime(shardingValue.getValueRange().upperEndpoint().toString()) : 
this.dateTimeUpper;
         LocalDateTime calculateTime = startTime;
   
         HashSet result;
         for(result = new HashSet(); !calculateTime.isAfter(endTime); 
calculateTime = calculateTime.plus((long)this.stepAmount, this.stepUnit)) {
             result.addAll(this.getMatchedTables(calculateTime, 
availableTargetNames));
         }
   
         result.addAll(this.getMatchedTables(endTime, availableTargetNames));
         return result;
     }
   }
   ```
   ### my application-sharding.yml
   ```
   
   dataSources:
     person: !!com.alibaba.druid.pool.DruidDataSource
       driverClassName: com.mysql.jdbc.Driver
       url: 
jdbc:mysql://localhost:3306/person?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
       username: root
       password: password
   
   rules:
     - !SHARDING
       tables:
         persons:
           actualDataNodes: person.persons
           tableStrategy:
             standard:
               shardingColumn: data_time
               shardingAlgorithmName: range_by_year
   
       shardingAlgorithms:
         range_by_year:
           type: INTERVAL
           props:
             datetime-pattern: "yyyy-MM-dd HH:mm:ss"
             datetime-lower: "1992-08-02 00:00:00"
             sharding-suffix-pattern: "yyyyMM"
             datetime-interval-amount: 1
             datetime-interval-unit: "YEARS"
   
       keyGenerators:
         snowflake:
           type: SNOWFLAKE
           props:
             worker-id: 123
   props:
     sql-show: true
   ```


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

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


Reply via email to