shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

动态表的actual-data-nodes

Open hanfre opened this issue 9 years ago • 7 comments

请问 新闻插入时,precise-algorithm-class是按照文章分类ID返回,也就是说表是插入的文章会分配到对应的分类表,例category_1034,category_235表等。插入没问题,我也会在建立分类后就建立表,这样插入更新删除是不影响的。

但是问题是查询有问题,会只查询 category这一个表,如果要进行select查询谋篇文章那么我actual-data-nodes这个参数怎么写呢?因为我也不知道"category_${ }"括号里的区间,因为id是分类ID,是动态的,请指教 非常感谢!

hanfre avatar Nov 23 '17 03:11 hanfre

请问动态表actual-data-node这个参数怎么写呢?还是有什么算法接口么?

hanfre avatar Nov 23 '17 03:11 hanfre

动态表的actual-data-node不用写

terrymanu avatar Nov 23 '17 03:11 terrymanu

我明白您的意思,而且我在做测试的时候这个参数也没有填写,所以插入更新删除都没问题,但是我查询的时候我看到的sql语句是select * from category 这表,不会从其他表查询,这个怎么破?

配置========= <sharding:data-source id="sd"> <sharding:sharding-rule data-source-names="sd0"> sharding:table-rules <sharding:table-rule logic-table="category" table-strategy-ref="category_TableShardingStrategy" generate-key-column="id" /> </sharding:table-rules> sharding:binding-table-rules <sharding:binding-table-rule logic-tables="category"/> </sharding:binding-table-rules> </sharding:sharding-rule> </sharding:data-source>

hanfre avatar Nov 23 '17 03:11 hanfre

这个问题我也遇到了,动态表没有起作用,错误信息如下: `Exception in thread "main" org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1

The error may exist in com/sjz/shardjdbc/dao/mapper/OrderMapper.java (best guess)

The error may involve defaultParameterMap

The error occurred while setting parameters

SQL: SELECT o.order_id orderId,o.status status ,oi.status itemStatus FROM t_order o ,t_order_item oi where o.order_id = oi.order_id

Cause: java.lang.IndexOutOfBoundsException: Index: 1, Size: 1

at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy72.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy75.listTest(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy76.listTest(Unknown Source)
at com.sjz.shardjdbc.service.OrderService.listTest(OrderService.java:77)
at com.sjz.shardjdbc.service.OrderService$$FastClassBySpringCGLIB$$a8080f0d.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at com.sjz.shardjdbc.service.OrderService$$EnhancerBySpringCGLIB$$d152f139.listTest(<generated>)
at com.sjz.shardjdbc.service.OrderService$$FastClassBySpringCGLIB$$a8080f0d.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at com.sjz.shardjdbc.service.OrderService$$EnhancerBySpringCGLIB$$559e3676.listTest(<generated>)
at com.sjz.shardjdbc.App.main(App.java:50)

Caused by: org.apache.ibatis.exceptions.PersistenceException: `

ejshi avatar Dec 29 '17 09:12 ejshi

我明白您的意思,而且我在做测试的时候这个参数也没有填写,所以插入更新删除都没问题,但是我查询的时候我看到的sql语句是select * from category 这表,不会从其他表查询,这个怎么破?

配置========= <sharding:data-source id="sd"> <sharding:sharding-rule data-source-names="sd0"> sharding:table-rules <sharding:table-rule logic-table="category" table-strategy-ref="category_TableShardingStrategy" generate-key-column="id" /> </sharding:table-rules> sharding:binding-table-rules <sharding:binding-table-rule logic-tables="category"/> </sharding:binding-table-rules> </sharding:sharding-rule> </sharding:data-source>

同问、、

wgou avatar Apr 18 '18 02:04 wgou

same problem, anybody ideas?

gitouyoung avatar Dec 06 '18 03:12 gitouyoung

Finally i find the cause for my situation: I use date as column name, and parser ignore it because it's a keyword. More keywords could be found in io.shardingsphere.core.parsing.lexer. may be helpful to u guys

gitouyoung avatar Dec 06 '18 06:12 gitouyoung