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/11/12 06:22:58 UTC

[GitHub] [incubator-shardingsphere] lyricsqq edited a comment on issue #3500: RangeShardingAlgorithm Range subquery ClassCastException

lyricsqq edited a comment on issue #3500: RangeShardingAlgorithm   Range subquery   ClassCastException
URL: https://github.com/apache/incubator-shardingsphere/issues/3500#issuecomment-552752531
 
 
   The following logical table of springboot configuration is the configuration when I have problems commented out by t ﹣ check ﹣ task. I now use the forced sharding to meet the needs of。
   
   ```
   spring:
     logpath: /home/logs/
     main:
       allow-bean-definition-overriding: true
     application:
       name: web
     shardingsphere:
       datasource:
         names: master
         master:
           type: com.zaxxer.hikari.HikariDataSource
           driver-class-name: com.mysql.cj.jdbc.Driver
           username: root
           password: wbxtest
           jdbcUrl: jdbc:mysql://xxxxxxx:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai
       sharding:
         tables:
           t_check_task:
             actual-data-nodes: master.t_check_task_$->{2017..2020}$->{['01','02','03','04','05','06','07','08','09','10','11','12']}
             key-generator:
               column: id
               type: SNOWFLAKE
             table-strategy:
               hint:
                 algorithm-class-name: com.wontex.inquiry.shard.Hint
             databaseStrategy:
               hint:
                 algorithm-class-name: com.wontex.inquiry.shard.Hint
             #  standard:
             #    sharding-column: executeTime
             #    rangeAlgorithmClassName: com.wontex.inquiry.shard.Range
             #    precise-algorithm-class-name: com.wontex.inquiry.shard.Precise
           t_base_defect_log:
             actual-data-nodes: master.t_base_defect_log_$->{2017..2020}$->{['01','02','03','04','05','06','07','08','09','10','11','12']}
             key-generator:
               column: id
               type: SNOWFLAKE
             table-strategy:
               inline:
                 sharding-column: createdTime
                 algorithm-expression: t_base_defect_log_$->{ if(createdTime!=null){ return createdTime.format("yyyyMM")}}
           t_base_defect_operate:
             actual-data-nodes: master.t_base_defect_operate_$->{2017..2020}$->{['01','02','03','04','05','06','07','08','09','10','11','12']}
             key-generator:
               column: id
               type: SNOWFLAKE
             table-strategy:
               inline:
                 sharding-column: createdTime
                 algorithm-expression: t_base_defect_operate_$->{ if(createdTime!=null){ return createdTime.format("yyyyMM")}}
           t_base_defect:
             actual-data-nodes: master.t_base_defect_$->{2017..2020}$->{['01','02','03','04','05','06','07','08','09','10','11','12']}
             key-generator:
               column: id
               type: SNOWFLAKE
             table-strategy:
               inline:
                 sharding-column: createdTime
                 algorithm-expression: t_base_defect_$->{ if(createdTime!=null){ return createdTime.format("yyyyMM")}}
       props:
         sql:
           show: true
   ```
   
   The implementation classes of fragmentation algorithm are as follows。
   
   ```
   package com.wontex.inquiry.shard;
   
   import com.alibaba.fastjson.JSON;
   import com.google.common.collect.Lists;
   import com.google.common.collect.Sets;
   import com.wontex.core.utils.DateUtil;
   import org.apache.shardingsphere.api.sharding.standard.RangeShardingAlgorithm;
   import org.apache.shardingsphere.api.sharding.standard.RangeShardingValue;
   import org.slf4j.Logger;
   import org.slf4j.LoggerFactory;
   
   import java.util.Collection;
   import java.util.Date;
   import java.util.List;
   import java.util.Set;
   
   public class Range implements RangeShardingAlgorithm<Date> {
       Logger logger = LoggerFactory.getLogger(Range.class);
   
       @Override
       public Collection<String> doSharding(Collection<String> availableTargetNames, RangeShardingValue<Date> shardingValue) {
           Date start = shardingValue.getValueRange().lowerEndpoint();
           Date end = shardingValue.getValueRange().upperEndpoint();
           int cr = DateUtil.getMonthsBetween(start, end);
           List<String> das = Lists.newArrayList();
           for (int i = 0; i < cr; i++) {
               Date date = DateUtil.addMonths(start, i + 1);
               das.add(DateUtil.formatDate(date, "yyyyMM"));
           }
           // 获取数据
           Set<String> tables = Sets.newTreeSet();
           //符合条件的表
           for (String da : das) {
               for (String target : availableTargetNames) {
                   if (target.contains(da)) {
                       tables.add(target);
                   }
               }
           }
           logger.info("目标表:" + JSON.toJSONString(tables));
           return tables;
       }
   }
   ```
   
   

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