-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Description
Question
For English only, other languages will not accept.
version:
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
<version>5.1.1</version>
</dependency>The shard key has no value, how to override the shardingjdbc source code to set the query table range, and query all tables without specifying it
分片key没有值,如何重写shardingjdbc源码,来设置查询表范围,不指定就查询了所有配置的表,
我的配置:
rules:
sharding:
# 数据分片配置
tables:
tab1:
actual-data-nodes: sharding_station.tab1_2022${['07','08','09','10','11','12']},sharding_station.tab1_$->{2023..2050}$->{(1..12).collect(i->i.toString().padLeft(2,'0'))}
# 分表策略
table-strategy:
standard:
# 分表字段
sharding-column: HAPPEN_TIME
# 自定义名称
sharding-algorithm-name: event-signal-his-alg
tab2:
actual-data-nodes: sharding_station.tab2_2022${['07','08','09','10','11','12']},sharding_station.tab2_$->{2023..2050}$->{(1..4).collect(i->i.toString().padLeft(2,'0'))}
table-strategy:
standard:
sharding-column: COLLECT_TIME
sharding-algorithm-name: target-collection-his-alg
# binding-tables: # 绑定表,也就是实际上哪些配置的sharidng表规则需要实际生效的列表,配置为yaml列表,并且允许单个条目中以逗号切割,所配置表必须已经配置为逻辑表
# - tab1,需要链表的表
# 分片算法配置
sharding-algorithms:
event-signal-his-alg: # 分片算法名称
type: CLASS_BASED # 声明类引用
props: # 分片算法属性配置
strategy: STANDARD
algorithmClassName: com.....YearMonthShardingAlgorithm
target-collection-his-alg:
type: CLASS_BASED
props:
strategy: STANDARD
algorithmClassName: com.....YearMonthShardingAlgorithmI have configured a custom sharding policy, but when the shard key is not specified or has no value, the custom sharding policy will not be used
我配置了自定义分片策略,但是当分片键不指定或者没有值时,是不会走自定义分片策略
Find many ways to intercept through SQL, but it is difficult to modify SQL and parse (SQL has more nested logic in SQL), so I want to modify the scope of the query table by rewriting the shardingjdbc source code, and give the shard key a start and end date
找了很多方法通过sql拦截,但是难度较大需要修改sql以及解析(sql内部嵌套逻辑较多),所以想通过重写shardingjdbc源码来修改查询表的范围,给分片键一个开始结束日期
Which class method in the source code should be rewritten to implement the requirements above
应该重写源码中的哪个类方法实现上面的需求