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 2019/12/16 09:42:03 UTC

[GitHub] [incubator-shardingsphere] fenghuanfun opened a new issue #3742: ComplexKeysShardingAlgorithm> Actual Use Suggestion

fenghuanfun opened a new issue #3742: ComplexKeysShardingAlgorithm<T extends Comparable<?>> Actual Use Suggestion
URL: https://github.com/apache/incubator-shardingsphere/issues/3742
 
 
   ## Feature Request
   ### Is your feature request related to a problem?
    - I report a bug in an issue, and it's version is ` sharding-jdbc-core:4.0.0-RC1 `
   [ComplexKeysShardingAlgorithm ClassCastException](https://github.com/apache/incubator-shardingsphere/issues/2613)
   - now it hava been fixed in  ` sharding-jdbc-core:4.0.0-RC3 `
   - However, i dont think it is the right way to resove this problem
   - example, in this ` ShardingAlgorithm ` 
   ```java
   public class BaseComplexKeysShardingAlgorithm implements ComplexKeysShardingAlgorithm<Timestamp> {
       @Override
       public Collection<String> doSharding(Collection<String> availableTargetNames, ComplexKeysShardingValue<Timestamp> shardingValue) {
           Range<Timestamp> range = shardingValue.getColumnNameAndRangeValuesMap().get("create_time");
           Timestamp timestamp = range.upperEndpoint();
           System.out.println(timestamp);
           return availableTargetNames;
       }
   }
   ```
         the field 'create_time' type is datetime(6) in mysql, java.sql.Timestamp in Java Entity
   - if the sql is ` select * from t_order where create_time = '2019-12-01 00:00:00.000000' ;`
    the `ShardingAlgorithm ` will receive a sharingValue that instance of Timestamp. 
   No problem so far.
   - However, if i use mysql function like `date_format`, the sql change to ` select * from t_order where date_fromat(create_time,'%Y-%m-%d') = '2019-12-01' ;` 
    it will receive ` ClassCastException` again when i try to get the sharding value. because the sharding value's type is `java.lang.String` indeed
   
   ### Describe the feature you would like.
   - in this sample, i think this situation exist in other mysql function too
   - so i suggest that `sharding-jdbc` should not just add a GenericType on `org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingAlgorithm<T extends Comparable<?>>`. 
   - GenericType limit that one field only have one type in a `ShardingAlgorithm`
   - Looking forward to your reply, thank you

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


With regards,
Apache Git Services