authorXiao opened a new issue #8924:
URL: https://github.com/apache/shardingsphere/issues/8924


   shardingsphere version  is  4.0.0-RC2
   shardingsphere Range Sharding Algorithm Unsupported >=;
   yaml:
   spring:
     application:
       name: demo
     shardingsphere:
      datasource:
         names: master
         master:
           type: com.alibaba.druid.pool.DruidDataSource
           driver-class-name: com.mysql.cj.jdbc.Driver
           url: 
jdbc:mysql://localhost:3306/rsr_battery?allowMultiQueries=true&autoReconnect=true&failOverReadOnly=false&useUnicode=true&characterEncoding=utf8&nullNamePatternMatchesAll=true&serverTimezone=Asia/Shanghai
           username: root
           password: a50k*7Ch1YTGYJW4
      sharding:
        binding-tables: test_copy
        tables:
          test_copy:
            actual-data-nodes: master.test_copy
            table-strategy:
              standard:
                sharding-column: gmt_date
                range-algorithm-class-name: 
com.demo.model.strategy.OrderProfitDetailPreciseShardingAlgorithm
                precise-algorithm-class-name: 
com.demo.model.strategy.OrderProfitDetailPreciseShardingAlgorithm
   OrderProfitDetailPreciseShardingAlgorithm.class
     public class OrderProfitDetailPreciseShardingAlgorithm implements  
PreciseShardingAlgorithm<String>,RangeShardingAlgorithm<String> {
   
        @Override
        public String doSharding(Collection<String> availableTargetNames, 
PreciseShardingValue<String> shardingValue) {
                for (String tableName : availableTargetNames) {
                        String value = shardingValue.getValue();
                        String dateStr =value.split("-")[0];
                        String mm =value.split("-")[1];
                        return 
tableName.concat("_").concat(dateStr).concat("_").concat(mm);
                }
                return  null;
        }
   
        @Override
        public Collection<String> doSharding(Collection<String> 
availableTargetNames,
                        RangeShardingValue<String> shardingValue) {
                  List<String> list = new ArrayList<String>();
                  Range<String> left = shardingValue.getValueRange();
                  String lowerEndpoint = left.lowerEndpoint();
                  String year = lowerEndpoint.split("-")[0];
                  String month = lowerEndpoint.split("-")[1];
                  for (String targetName : availableTargetNames) {
                          
list.add(targetName.concat("_").concat(year).concat("_").concat(month));
                }
                  return list;
        }
   
   
   }
   xml:
     <select id="findUserByGmtDate" parameterType="String" 
resultType="com.demo.model.User">
           SELECT t.*
           FROM test_copy t
           left  join  test_copy c on  c.id=t.id
           WHERE t.gmt_date>=#{date}
       </select>
     


----------------------------------------------------------------
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:
[email protected]


Reply via email to