You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/11/30 03:41:47 UTC
[GitHub] [shardingsphere] fyname opened a new issue #13857: Cannot use mod() on this number type: java.math.BigDecimal
fyname opened a new issue #13857:
URL: https://github.com/apache/shardingsphere/issues/13857
## Bug Report
### Which version of ShardingSphere did you use?
version: 5
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
use: shardingsphere-jdbc
### Expected behavior
The supported split table field type is BigInteger
### Actual behavior
The supported split table field type is BigInteger
### Reason analyze (If you can)
First:
Actual order_ No is BigInteger
However, inlineshardingalgorithm groovy automatically recognizes that the sub table field is of BigDecimal type
Second:
The distribution only supports integer segmentation;
Caused by: java.lang.UnsupportedOperationException: Cannot use mod() on this number type: java.math.BigDecimal with value: 1638242445307000001
at org.codehaus.groovy.runtime.typehandling.NumberMath.createUnsupportedException(NumberMath.java:269)
at org.codehaus.groovy.runtime.typehandling.NumberMath.modImpl(NumberMath.java:249)
at org.codehaus.groovy.runtime.typehandling.NumberMath.mod(NumberMath.java:92)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.mod(DefaultGroovyMethods.java:14516)
at org.codehaus.groovy.runtime.dgm$439.invoke(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
at Script7$_run_closure1.doCall(Script7.groovy:1)
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:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:264)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1034)
at groovy.lang.Closure.call(Closure.java:420)
at groovy.lang.Closure.call(Closure.java:414)
at org.apache.shardingsphere.sharding.algorithm.sharding.inline.InlineShardingAlgorithm.doSharding(InlineShardingAlgorithm.java:70)
at org.apache.shardingsphere.sharding.route.strategy.type.standard.StandardShardingStrategy.doSharding(StandardShardingStrategy.java:68)
at org.apache.shardingsphere.sharding.route.strategy.type.standard.StandardShardingStrategy.doSharding(StandardShardingStrategy.java:57)
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeTables(ShardingStandardRoutingEngine.java:218)
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.route0(ShardingStandardRoutingEngine.java:198)
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeByShardingConditionsWithCondition(ShardingStandardRoutingEngine.java:118)
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeByShardingConditions(ShardingStandardRoutingEngine.java:111)
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.getDataNodes(ShardingStandardRoutingEngine.java:88)
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.route(ShardingStandardRoutingEngine.java:70)
at org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.createRouteContext(ShardingSQLRouter.java:56)
at org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.createRouteContext(ShardingSQLRouter.java:44)
at org.apache.shardingsphere.infra.route.engine.impl.PartialSQLRouteExecutor.route(PartialSQLRouteExecutor.java:62)
at org.apache.shardingsphere.infra.route.engine.SQLRouteEngine.route(SQLRouteEngine.java:53)
at org.apache.shardingsphere.infra.context.kernel.KernelProcessor.route(KernelProcessor.java:54)
at org.apache.shardingsphere.infra.context.kernel.KernelProcessor.generateExecutionContext(KernelProcessor.java:46)
at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.createExecutionContext(ShardingSpherePreparedStatement.java:378)
at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.execute(ShardingSpherePreparedStatement.java:286)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:47)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)
... 72 more
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] fyname commented on issue #13857: Cannot use mod() on this number type: java.math.BigDecimal
Posted by GitBox <gi...@apache.org>.
fyname commented on issue #13857:
URL: https://github.com/apache/shardingsphere/issues/13857#issuecomment-982326810
> OK , @fyname , in your table, `order_no` is of type BigInteger. So in your Java application, is `order_no` a Long type?
@Data
public class Order {
private int id;
private int user_id;
private BigInteger order_no;
private Timestamp order_time;
private String merchant;
}
use BigInteger
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] RaigorJiang commented on issue #13857: Cannot use mod() on this number type: java.math.BigDecimal
Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on issue #13857:
URL: https://github.com/apache/shardingsphere/issues/13857#issuecomment-982329855
`java.math.BigInteger` is not suitable, `Long` should be used.
In mysql, bigint is a long integer, corresponding to Long in Java:
https://dev.mysql.com/doc/refman/8.0/en/integer-types.html
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] fyname closed issue #13857: Cannot use mod() on this number type: java.math.BigDecimal
Posted by GitBox <gi...@apache.org>.
fyname closed issue #13857:
URL: https://github.com/apache/shardingsphere/issues/13857
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] fyname commented on issue #13857: Cannot use mod() on this number type: java.math.BigDecimal
Posted by GitBox <gi...@apache.org>.
fyname commented on issue #13857:
URL: https://github.com/apache/shardingsphere/issues/13857#issuecomment-982304633
> Hi @fyname Can you show your algorithm configuration?
rules:
sharding:
tables:
tb_order:
actualDataNodes: tmall.tb_order_$->{0..1},taobao.tb_order_$->{0..1},aliyun.tb_order_$->{0..1}
keyGenerateStrategy:
column: order_id
keyGeneratorName: snowflake
table-strategy:
standard:
sharding-column: order_no
sharding-algorithm-name: tb-order-inline
defaultDatabaseStrategy:
standard:
shardingColumn: merchant
shardingAlgorithmName: db-classbased
defaultTableStrategy:
none:
shardingAlgorithms:
db-classbased:
type: CLASS_BASED
props:
strategy: standard
algorithmClassName: com.freesun.shardingsphere.multitenancy.spi.DbShardingAlgorithm
tb-order-inline:
type: INLINE
props:
algorithm-expression: tb_order_$->{order_no % 2}
keyGenerators:
snowflake:
type: SNOWFLAKE
props:
worker-id: 123
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] RaigorJiang commented on issue #13857: Cannot use mod() on this number type: java.math.BigDecimal
Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on issue #13857:
URL: https://github.com/apache/shardingsphere/issues/13857#issuecomment-982293150
Hi @fyname
Can you show your algorithm configuration?
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] RaigorJiang edited a comment on issue #13857: Cannot use mod() on this number type: java.math.BigDecimal
Posted by GitBox <gi...@apache.org>.
RaigorJiang edited a comment on issue #13857:
URL: https://github.com/apache/shardingsphere/issues/13857#issuecomment-982326265
OK , @fyname ,
in your table, `order_no` is of type BigInteger. So in your Java application, is `order_no` a Long type?
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] RaigorJiang commented on issue #13857: Cannot use mod() on this number type: java.math.BigDecimal
Posted by GitBox <gi...@apache.org>.
RaigorJiang commented on issue #13857:
URL: https://github.com/apache/shardingsphere/issues/13857#issuecomment-982326265
OK , @fyname
Okay, in your table, `order_no` is of type BigInteger. So in your Java application, is `order_no` a Long type?
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] fyname commented on issue #13857: Cannot use mod() on this number type: java.math.BigDecimal
Posted by GitBox <gi...@apache.org>.
fyname commented on issue #13857:
URL: https://github.com/apache/shardingsphere/issues/13857#issuecomment-982335234
> `java.math.BigInteger` is not suitable, `Long` should be used.
>
> In mysql, bigint is a long integer, corresponding to Long in Java: https://dev.mysql.com/doc/refman/8.0/en/integer-types.html
thanks
--
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: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org