jianliu opened a new issue #10735:
URL: https://github.com/apache/shardingsphere/issues/10735


   ## Bug Report
   
   ### Which version of ShardingSphere did you use?
   master branch
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   ShardingSphere-Proxy & governance
   
   ### Expected behavior
   table columns: id(bigint)\create_at(datetime)
   table sharding algorithm: INTERVAL
   actualDataNodes:
   
ds_0.time_test_20210607,ds_0.time_test_20210614,ds_0.time_test_20210621,...,ds_1
   props:
   ```
        time_test_interval:
         type: INTERVAL
         props:
           datetime-lower: '2020-01-01 00:00:00'
           datetime-interval-unit: weeks
           datetime-interval-amount: 1
           datetime-pattern: yyyy-MM-dd HH:mm:ss
           sharding-suffix-pattern: yyyyMMdd
   ```
   only 
   ``` 
   INSERT INTO `time_test` (`create_at`) VALUES ('2021-06-07 03:01:01');
   INSERT INTO `time_test` (`create_at`) VALUES ('2021-06-14 03:01:01');
   ``` 
   could insert success
   I wish datetime like  2021-06-09 03:01:01  other datetime thant not in 
actualDataNodes could success
   and 2021-06-09 03:01:01 insert into time_test_20210607,
   2021-06-19 03:01:01 insert into time_test_20210614. make it easy to use.
   
   ### Actual behavior
   if the create_at value is 2021-06-09 03:01:01 or other datetime thant not in 
actualDataNodes will occur error like
   ``` 
   <e>查询:insert into `time_test` (`create_at`) values ('2021-06-13 03:01:01')
   
   错误代码: 1064
   You have an error in your SQL syntax; check the manual that corresponds to 
your MySQL server version for the right syntax to use near 
'.shardingsphere.sharding.rewrite.token.pojo.TableToken@4357801e (`create_at`, 
id' at line 1
   ```
   
   ### Reason analyze (If you can)
   
![image](https://user-images.githubusercontent.com/1589099/121327845-67205d00-c946-11eb-86c0-ced5cbca7379.png)
   The reason here is judge by endsWith
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   
   ### Example codes for reproduce this issue (such as a github link).
   If when we want to achieve the goal like this:
   ``` 
   2021-06-09 03:01:01 insert into time_test_20210607,
   2021-06-19 03:01:01 insert into time_test_20210614. 
   ```
   With timebase algorithm, availableTargetNames should to be sorted in nature 
way when created,
   ``` 
       public String doSharding(final Collection<String> availableTargetNames, 
final PreciseShardingValue<Comparable<?>> shardingValue) {
           return availableTargetNames.stream()
                   .filter(each -> 
each.endsWith(parseDateTime(shardingValue.getValue().toString()).format(tableSuffixPattern)))
                   .findFirst().orElseThrow(() -> new 
ShardingAlgorithmException(String.format("failed to shard value %s, and 
availableTables %s", shardingValue, availableTargetNames)));
       }
   ``` 
   when doSharding when insert or delete,update,could route like this:
   
![image](https://user-images.githubusercontent.com/1589099/121328954-58867580-c947-11eb-8776-6fc755db5154.png)
   
   If you think this is a problem,I`d like to resolve 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.

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


Reply via email to