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 2021/06/09 09:26:13 UTC

[GitHub] [shardingsphere] jianliu opened a new issue #10735: Using IntervalShardingAlgorithm with config `datetime-interval-unit` is great than days occur error when datatime insert

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:
users@infra.apache.org



[GitHub] [shardingsphere] jianliu commented on issue #10735: Using IntervalShardingAlgorithm with config `datetime-interval-unit` greater than 'days' occur error when insert

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


   @strongduanmu Thank you for answer,  your suggests did solve this problem,I`ll close this issuse.


-- 
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:
users@infra.apache.org



[GitHub] [shardingsphere] strongduanmu commented on issue #10735: Using IntervalShardingAlgorithm with config `datetime-interval-unit` greater than 'days' occur error when insert

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


   @jianliu Thank you very much for your feedback. Using `IntervalShardingAlgorithm` requires us to configure the `datetime-interval-unit` and `datetime-pattern` parameters to be consistent. If `datetime-interval-unit` is set to `weeks`, then `datetime-pattern` needs to be set to the corresponding format, such as `yyyyww`. You can modify your `datetime-pattern` parameter to see if the problem is solved. 


-- 
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:
users@infra.apache.org



[GitHub] [shardingsphere] jianliu removed a comment on issue #10735: Using IntervalShardingAlgorithm with config `datetime-interval-unit` greater than 'days' occur error when insert

Posted by GitBox <gi...@apache.org>.
jianliu removed a comment on issue #10735:
URL: https://github.com/apache/shardingsphere/issues/10735#issuecomment-857557777


   Make corrections of "Actual behavior "
   the default behavior is thrown excpetion like:
   ```
   Unknown exception: [failed to shard value PreciseShardingValue(logicTableName=time_test, columnName=create_at, value=2021-06-13 03:01:01), and availableTables [time_test_20210607, time_test_20210614, time_test_20210621, time_test_20210628, time_test_20210705, time_test_20210712, time_test_20210719, time_test_20210726, time_test_20210802, time_test_20210809, time_test_20210816, time_test_20210823, time_test_20210830, time_test_20210906, time_test_20210913, time_test_20210920, time_test_20210927, time_test_2 
   ```
   Because of another bug of multi ds use unique table name like ds1.t1,   ds1.t2,   ds2.t3 ,    ds2.t4, so I modify the code like this
   ```
       @Override
       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().orElse(null);  //when not hit table,return null
       }
   ```
   So finally the error becames:
   ```    
        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
   ```
   
   Sorry for misdescribe.


-- 
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:
users@infra.apache.org



[GitHub] [shardingsphere] jianliu commented on issue #10735: Using IntervalShardingAlgorithm with config `datetime-interval-unit` is great than days occur error when datatime insert

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


   Make corrections of "Actual behavior "
   the default behavior is thrown excpetion like:
   ```
   Unknown exception: [failed to shard value PreciseShardingValue(logicTableName=time_test, columnName=create_at, value=2021-06-13 03:01:01), and availableTables [time_test_20210607, time_test_20210614, time_test_20210621, time_test_20210628, time_test_20210705, time_test_20210712, time_test_20210719, time_test_20210726, time_test_20210802, time_test_20210809, time_test_20210816, time_test_20210823, time_test_20210830, time_test_20210906, time_test_20210913, time_test_20210920, time_test_20210927, time_test_2 
   ```
   Because of another bug of multi ds use unique table name like ds1.t1,   ds1.t2,   ds2.t3 ,    ds2.t4, so I modify the code like this
   ```
       @Override
       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().orElse(null);  //when not hit table,return null
       }
   ```
   So finally the error becames:
   ```    
        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
   ```
   
   Sorry for misdescribe.


-- 
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:
users@infra.apache.org



[GitHub] [shardingsphere] jianliu closed issue #10735: Using IntervalShardingAlgorithm with config `datetime-interval-unit` greater than 'days' occur error when insert

Posted by GitBox <gi...@apache.org>.
jianliu closed issue #10735:
URL: https://github.com/apache/shardingsphere/issues/10735


   


-- 
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:
users@infra.apache.org