lssprogress commented on issue #3869: version:4.0.0-RC1 group by bug
URL: 
https://github.com/apache/incubator-shardingsphere/issues/3869#issuecomment-571868530
 
 
   @Slf4j
   public class OrderTableShardingAlgorithm implements 
PreciseShardingAlgorithm<String>, RangeShardingAlgorithm<String> {
   
       @Override
       public String doSharding(Collection<String> collection, 
PreciseShardingValue<String> preciseShardingValue) {
           String tableNode=null;
           Date createDate = 
DateUtil.parseDateFromStrYyyyMMdd2(preciseShardingValue.getValue());
           Calendar c = Calendar.getInstance();
           c.setTime(createDate);
           int year = c.get(Calendar.YEAR);
           int season = DateUtil.getSeason(createDate);
   
           log.debug("按照季度进行数据分片,精准查询,当前为第{}年,第{}季度:",year,season);
           for(Object obj:collection){
               String oneNode=obj+"";
               if(oneNode.endsWith(year+""+season)){
                   tableNode = oneNode;
                   break;
               }
           }
   
          return tableNode;
       }
   
       @Override
       public Collection<String> doSharding(Collection<String> collection, 
RangeShardingValue<String> rangeShardingValue) {
           Collection<String> collect = new ArrayList<>();
           Calendar calendar=Calendar.getInstance();
           String 
dateUpperStr=rangeShardingValue.getValueRange().upperEndpoint();
           String 
dateLowerStr=rangeShardingValue.getValueRange().lowerEndpoint();
           Date dateUpper=DateUtil.parseDateFromStrYyyyMMdd2(dateUpperStr);
           Date dateLower=DateUtil.parseDateFromStrYyyyMMdd2(dateLowerStr);
   
           calendar.setTime(dateUpper);
           int yearUpper=calendar.get(Calendar.YEAR);
           int seasonUpper = DateUtil.getSeason(dateUpper);
   
           calendar.setTime(dateLower);
           int yearLower=calendar.get(Calendar.YEAR);
           int seasonLower = DateUtil.getSeason(dateLower);
           boolean add = false;
           for(String obj:collection){
               String tableNoe=obj+"";
               if(!add){
                   if(tableNoe.endsWith(yearLower+""+seasonLower)){
                       add = true;
                   }
               }
               if(tableNoe.endsWith(yearUpper+""+seasonUpper)){
                   collect.add(tableNoe);
                   break;
               }
               if(add){
                   collect.add(tableNoe);
               }
           }
           log.debug("按照季度进行数据分片,范围查询,当前范围:{}", JSONUtil.parseArray(collect));
           return collect;
       }
   }

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


With regards,
Apache Git Services

Reply via email to