方便更快捷的说明问题,可以按需填写(可删除)
使用环境:使用版本5.0 ,项目为springboot
场景、问题:跨库关联查询遇到报错
已进行操作:
这是我的配置参数。
由于该功能目前还是实验性功能,默认关闭,请设置 sql-federation-enabled 开启 federation 分布式查询功能。
我配置了spring.shardingsphere.props.sql-federation-enabled=true属性,然后没查出来数据,见上一条回复内容。
另外烦请看下我配置的这些属性没啥问题吧?
感谢补充信息,我来看下
配置信息如下:
spring.shardingsphere.rules.sharding.tables.report_site_day.actual-data-nodes=ds$->{2015…2021}.report_site_day
spring.shardingsphere.props.sql-show=true
spring.shardingsphere.props.sql-simple=true
spring.shardingsphere.props.sql-federation-enabled=true
spring.shardingsphere.rules.sharding.tables.report_site_day.database-strategy.standard.sharding-column=datatime
spring.shardingsphere.rules.sharding.tables.report_site_day.database-strategy.standard.sharding-algorithm-name=my-db-range-sharding-algorithm
spring.shardingsphere.rules.sharding.sharding-algorithms.my-db-range-sharding-algorithm.type=CLASS_BASED
spring.shardingsphere.rules.sharding.sharding-algorithms.my-db-range-sharding-algorithm.props.strategy=standard
spring.shardingsphere.rules.sharding.sharding-algorithms.my-db-range-sharding-algorithm.props.algorithmClassName=cn.cicoding.jdbc.db.table.algorithm.MyDBRangeShardingAlgorithm
看起来没什么问题.方便贴一下CLASS_BASE的对应类?
这,没有实现 public String getType()
和public void init()
两个函数?
开了sql-simple?完整的执行sql是?为什么会有个ds0?
啊?这两个也需要实现?有demo代码?
ds0是主库,ds2021是分库,是这样的。
同样是org.apache.shardingsphere.example.extension.sharding.algortihm.classbased.fixture.ClassBasedStandardShardingAlgorithmFixture
内,CLASS_BASE的返回值return null,而init()函数体内为空.
我只是用到数据分片。2015-2021是分库。
这里是关键的属性设置
spring.shardingsphere.datasource.names=ds0,ds2015,ds2016,ds2017,ds2018,ds2019,ds2020,ds2021
spring.shardingsphere.datasource.ds0.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds0.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.ds0.jdbc-url=jdbc:mysql://localhost:3306/ipvacloud?useSSL=false&useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
spring.shardingsphere.datasource.ds0.username=root
spring.shardingsphere.datasource.ds0.password=admin
spring.shardingsphere.datasource.ds2015.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds2015.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.ds2015.jdbc-url=jdbc:mysql://localhost:3306/ipvacloud_ramus_2015?useSSL=false&useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
spring.shardingsphere.datasource.ds2015.username=root
spring.shardingsphere.datasource.ds2015.password=admin
spring.shardingsphere.rules.sharding.tables.report_site_day.actual-data-nodes=ds$->{2015…2021}.report_site_day
spring.shardingsphere.rules.sharding.tables.report_site_day.database-strategy.standard.sharding-column=datatime
spring.shardingsphere.rules.sharding.tables.report_site_day.database-strategy.standard.sharding-algorithm-name=my-db-range-sharding-algorithm
spring.shardingsphere.rules.sharding.sharding-algorithms.my-db-range-sharding-algorithm.type=CLASS_BASED
spring.shardingsphere.rules.sharding.sharding-algorithms.my-db-range-sharding-algorithm.props.strategy=standard
spring.shardingsphere.rules.sharding.sharding-algorithms.my-db-range-sharding-algorithm.props.algorithmClassName=cn.cicoding.jdbc.db.table.algorithm.MyDBRangeShardingAlgorithm
spring.shardingsphere.props.sql-show=true
spring.shardingsphere.props.sql-simple=true
spring.shardingsphere.props.sql-federation-enabled=true
另外我是指分库不分表的场景。