Comments (7)
My configuration :
java.util.Properties propertiesForTEntOrderItem = new java.util.Properties();
propertiesForTEntOrderItem.setProperty("algorithm-expression", "t_ent_order_item_${order_id % 2}");
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration algorithmConfigurationForTEntOrderItem = new org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration("INLINE", propertiesForTEntOrderItem);
stringAlgorithmConfigurationMap.put("t_ent_order_item_line", algorithmConfigurationForTEntOrderItem);
ShardingTableRuleConfiguration shardingTableRuleConfiguration = new ShardingTableRuleConfiguration("t_ent_order_item", "ds_${0..3}.t_ent_order_item_${[0, 1, 2, 3, 4, 5, 6, 7]}");
shardingTableRuleConfiguration.setKeyGenerateStrategy(new KeyGenerateStrategyConfiguration("id", "snowflake"));
shardingTableRuleConfiguration.setTableShardingStrategy(new StandardShardingStrategyConfiguration("order_id", "t_ent_order_item_line"));
from shardingsphere.
"t_ent_order_item", "ds_${0..3}.t_ent_order_item_${[0, 1, 2, 3, 4, 5, 6, 7]}",是要分 8个表 , 算法algorithm-expression=t_ent_order_item_${order_id % 8} 必须是 order_id % 8
from shardingsphere.
我把算法表达式改成propertiesForTEntOrderItem.setProperty("algorithm-expression", "t_ent_order_item_${order_id % 8}");
from shardingsphere.
还是不行,报同样的错误
from shardingsphere.
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO t_ent_order_item(ent_id, region_code, good_id, good_name, order_id) VALUES (?, ?, ?, ?, ?);");
preparedStatement.setInt(1, 2024);
preparedStatement.setString(2, "GD");
preparedStatement.setString(3, "abc123");
preparedStatement.setString(4, "研究ShardingSphere");
preparedStatement.setInt(5, 16);
int result = preparedStatement.executeUpdate();
System.out.println("打印插入结果->" + result);
我通过这段代码插入一条记录然后就抛出如下异常:
java.sql.SQLException: Please check your sharding conditions 'ShardingConditions(conditions=[ShardingCondition(values=[t_ent_order_item.order_id = 16], startIndex=0)], sqlStatementContext=org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext@600428ad, rule=org.apache.shardingsphere.sharding.rule.ShardingRule@5342032a, subqueryContainsShardingCondition=true)' to avoid same record in table 't_ent_order_item' routing to multiple data nodes.
at org.apache.shardingsphere.infra.exception.core.external.sql.ShardingSphereSQLException.toSQLException(ShardingSphereSQLException.java:76)
at org.apache.shardingsphere.infra.exception.dialect.SQLExceptionTransformEngine.toSQLException(SQLExceptionTransformEngine.java:54)
at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.executeUpdate(ShardingSpherePreparedStatement.java:367)
at com.example.shardingsphere.ShardingsphereApplication.main(ShardingsphereApplication.java:57)
from shardingsphere.
Hi @JianfeiMa, can you modify the issue title for search friendly?
from shardingsphere.
问题原因是:
当分片表规则配置的实际数据节点是这样demo_ds_${0,1}.t_order_${[0, 1]}的时候,最终会拆分成笛卡尔乘积,所以在查询的时候会分别查询两个数据的两个表,但是当插入数据的时候就抛出以上错误,当我改成demo_ds_${0}.t_order_${[0, 1]}再次插入数据的时候就不会抛出异常了;如果要路由多个数据库的时候又该如何配置呢?
from shardingsphere.
Related Issues (20)
- Refactor the acquisition of ContextManager in JDBC metrics
- Can not get 36 connections one time, partition succeed connection(10) have released HOT 2
- java.sql.SQLFeatureNotSupportedException: can't get index from columnLabel[field_2] HOT 2
- EXECUTE ENGINE question
- when i use shardingjdbc 5.3.2 i got a problem, org.hibernate.engine.jdbc.createBlob is not support? HOT 2
- Table or view `t_ent_order` does not exist HOT 5
- sharding table column field lose HOT 1
- Improve pointcut configuration for agent
- ShardingSphere and PostgreSQL rollback only issue
- Got a error: UnknownColumnException: Unknown column. Maybe a bug ? HOT 7
- NPE : Cannot invoke "javax.sql.DataSource.getConnection()" because "this.dataSource" is null when unregister storage unit
- [code conduct] There are a lot of indents in the g4 files that shouldn't be there HOT 4
- Support federated query mysql length function
- Support federated query mysql bit_length function
- Support federated query mysql LOCATE function
- change authority config and restart shardingsphere-proxy, not work HOT 2
- 自带的SnowflakeKeyGenerateAlgorithm id雪花生成器,批量多次调用 第一个一次调用永远是偶数的问题 HOT 1
- Improve the federated query MySQL function HOT 1
- Seems can't support order by after merge from multi tables
- ERROR o.s.j.d.DataSourceTransactionManager-Commit exception overridden by rollback exception HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shardingsphere.