DragonZhang123 opened a new issue, #36147:
URL: https://github.com/apache/shardingsphere/issues/36147

   Two distinct sharding algorithms (YearTableShardingAlgorithm and 
MonthTableShardingAlgorithm) are defined in the ShardingSphere configuration 
file. However, at runtime, all tables use the first algorithm listed in the 
configuration, leading to incorrect sharding logic.
    
   Which version of ShardingSphere did you use?
   5.5.1
   Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   ShardingSphere-JDBC
   Expected behavior
   Table t_year_table should use YearTableShardingAlgorithm (sharding by year).
   Table t_month_table should use MonthTableShardingAlgorithm (sharding by 
month).
   Actual behavior
   Both t_year_table and t_month_table use YearTableShardingAlgorithm (the 
first algorithm defined in the configuration).
   Reason analyze (If you can)
   Sharding algorithm instances in the configuration may be overwritten (e.g., 
singleton pattern causes duplicate registration).
   ShardingSphere fails to parse the algorithm order in the configuration, 
prioritizing the first instance.
   Custom algorithms are not correctly bound to their shardingColumn or 
shardingAlgorithmName.
   
      rules:
        - !SHARDING
          tables:
            t_year_table:
              actualDataNodes: ds0.t_year_table_$->{2020..2025}
              tableStrategy:
                standard:
                  shardingColumn: year_date
                  shardingAlgorithmName: year_algorithm
            t_month_table:
              actualDataNodes: ds0.t_month_table_$->{202001..202512}
              tableStrategy:
                standard:
                  shardingColumn: month_date
                  shardingAlgorithmName: month_algorithm
          shardingAlgorithms:
            year_algorithm:
              type: CLASS_BASED
              props:
                strategy: STANDARD
                algorithmClassName: com.example.YearTableShardingAlgorithm
            month_algorithm:
              type: CLASS_BASED
              props:
                strategy: STANDARD
                algorithmClassName: com.example.MonthTableShardingAlgorithm
         // YearTableShardingAlgorithm.java
      public class YearTableShardingAlgorithm implements 
StandardShardingAlgorithm<Date> {
          private static final String TABLE_PATTERN = "t_year_table_%04d";
          // Implement year-based sharding logic
      }
   
      // MonthTableShardingAlgorithm.java
      public class MonthTableShardingAlgorithm implements 
StandardShardingAlgorithm<Date> {
          private static final String TABLE_PATTERN = "t_month_table_%04d%02d";
          // Implement month-based sharding logic
      }
      


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

To unsubscribe, e-mail: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to