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/04/02 02:45:48 UTC

[GitHub] [shardingsphere] wangkang09 opened a new issue #9911: custom ShardingUpdateStatementValidator and invailld default ShardingUpdateStatementValidator

wangkang09 opened a new issue #9911:
URL: https://github.com/apache/shardingsphere/issues/9911


   
   version:4.1.1
   sharing strategy: complex sharding strategy
   sharing column: memberId、referenceNum
   
   my sharding column are memberId and billno,but the real sharding column is memberId。if in the where condition only have referenceNum,We will calculate memberId by referenceNum,and sharding by the calculated memberId。
   
   but,the default ShardingUpdateStatementValidator  will throw excption : Can not update sharding key!
   with the follow sql:
   update order set referenceNum= xx where memberId = xx
   
   i want custom ShardingUpdateStatementValidator and invailld default ShardingUpdateStatementValidator。but i cannot find a good way。i can custom a ShardingRouteDecorator,but the default ShardingRouteDecorator will also vaild


-- 
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] wangkang09 commented on issue #9911: custom ShardingUpdateStatementValidator and invailld default ShardingUpdateStatementValidator

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


   if the ShardingStatementValidatorFactory can use SPI,it will be nice


-- 
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] wangkang09 commented on issue #9911: custom ShardingUpdateStatementValidator and invailld default ShardingUpdateStatementValidator

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


   > Thank you for your reply。this is my sharding algorithm
   > 
   > ```java
   > @Slf4j
   > public class DbComplexAlgorithm implements ComplexKeysShardingAlgorithm<Comparable<?>> {
   >     @Override
   >     public Collection<String> doSharding(Collection<String> availableTargetNames, ComplexKeysShardingValue<Comparable<?>> shardingValue) {
   >         Map<String, Collection<Comparable<?>>> shardingMap = shardingValue.getColumnNameAndShardingValuesMap();
   >         Collection<Comparable<?>> memberIdList = shardingMap.get("member_id");
   >         //For historical reasons, the where conditions may not have member_id column
   >         if (CollectionUtils.isNotEmpty(memberIdList)) {
   >             return getDbs(memberIdList);
   >         }
   > 
   >         //so,we add a additional sharding key : billno
   >         Collection<Comparable<?>> billnoList = shardingMap.get("billno");
   >         //to get memberIds
   >         List<Long> memberId = getMemberIdFromEs(billnoList);
   >         return getDbs(memberId);
   >     }
   > ```
   
   
   
   > Thank you for your reply。this is my sharding algorithm
   > 
   > ```java
   > @Slf4j
   > public class DbComplexAlgorithm implements ComplexKeysShardingAlgorithm<Comparable<?>> {
   >     @Override
   >     public Collection<String> doSharding(Collection<String> availableTargetNames, ComplexKeysShardingValue<Comparable<?>> shardingValue) {
   >         Map<String, Collection<Comparable<?>>> shardingMap = shardingValue.getColumnNameAndShardingValuesMap();
   >         Collection<Comparable<?>> memberIdList = shardingMap.get("member_id");
   >         //For historical reasons, the where conditions may not have member_id column
   >         if (CollectionUtils.isNotEmpty(memberIdList)) {
   >             return getDbs(memberIdList);
   >         }
   > 
   >         //so,we add a additional sharding key : billno
   >         Collection<Comparable<?>> billnoList = shardingMap.get("billno");
   >         //to get memberIds
   >         List<Long> memberId = getMemberIdFromEs(billnoList);
   >         return getDbs(memberId);
   >     }
   > ```
   
   @dongzl 


-- 
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] dongzl commented on issue #9911: custom ShardingUpdateStatementValidator and invailld default ShardingUpdateStatementValidator

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


   `my sharding column are memberId and billno,but the real sharding column is memberId。`
   
   Hi @wangkang09 , what's the meaning of it?  why the configuration include two sharding column, but actually only one?
   
   can you provide the configuration of your project?


-- 
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] wangkang09 commented on issue #9911: custom ShardingUpdateStatementValidator and invailld default ShardingUpdateStatementValidator

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


   Thank you for your reply。this is my sharding algorithm
   ```java
   @Slf4j
   public class DbComplexAlgorithm implements ComplexKeysShardingAlgorithm<Comparable<?>> {
       @Override
       public Collection<String> doSharding(Collection<String> availableTargetNames, ComplexKeysShardingValue<Comparable<?>> shardingValue) {
           Map<String, Collection<Comparable<?>>> shardingMap = shardingValue.getColumnNameAndShardingValuesMap();
           Collection<Comparable<?>> memberIdList = shardingMap.get("member_id");
           //For historical reasons, the where conditions may not have member_id column
           if (CollectionUtils.isNotEmpty(memberIdList)) {
               return getDbs(memberIdList);
           }
   
           //so,we add a additional sharding key : billno
           Collection<Comparable<?>> billnoList = shardingMap.get("billno");
           //to get memberIds
           List<Long> memberId = getMemberIdFromEs(billnoList);
           return getDbs(memberId);
       }
   ```


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