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 2022/07/08 09:32:41 UTC
[GitHub] [shardingsphere] chenliang7558 opened a new issue, #18961: 5.1.2-ShardingProxy java.lang.Integer cannot be cast to java.lang.Long
chenliang7558 opened a new issue, #18961:
URL: https://github.com/apache/shardingsphere/issues/18961
## Bug Report
**For English only**, other languages will not accept.
Before report a bug, make sure you have:
- Searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues).
- Read documentation: [ShardingSphere Doc](https://shardingsphere.apache.org/document/current/en/overview).
Please pay attention on issues you submitted, because we maybe need more details.
If no response anymore and we cannot reproduce it on current information, we will **close it**.
Please answer these questions before submitting your issue. Thanks!
### Which version of ShardingSphere did you use?
5.1.2
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
proxy
### Expected behavior
I use custom algorithm in shardingsphere-proxy, the version is 5.1.2 ,and config is :
```
schemaName: orders
dataSources:
db_0:
url: jdbc:mysql://127.0.0.1:3306/db_0?serverTimezone=Asia/Shanghai&useSSL=false
username: root
password: 123456
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 10
db_1:
url: jdbc:mysql://127.0.0.1:3306/db_1?serverTimezone=Asia/Shanghai&useSSL=false
username: root
password: 123456
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 10
rules:
- !SHARDING
tables:
t_order:
actualDataNodes: db_${0..1}.t_order_${0..3}
tableStrategy:
standard:
shardingColumn: user_id
shardingAlgorithmName: t_order_inline
defaultDatabaseStrategy:
standard:
shardingColumn: order_id
shardingAlgorithmName: db_modulo
defaultTableStrategy:
none:
shardingAlgorithms:
db_modulo:
type: CUSTOM_SHARD
t_order_inline:
type: INLINE
props:
algorithm-expression: t_order_${user_id % 2}
```
my MySQL version is 5.6.48; create table sql:
```
create database db_0;
CREATE TABLE `t_order_0` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`order_id` bigint(20) DEFAULT NULL,
`user_id` bigint(20) DEFAULT NULL,
`status` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `t_order_1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`order_id` bigint(20) DEFAULT NULL,
`user_id` bigint(20) DEFAULT NULL,
`status` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
create database db_1;
...
```
my custom algorithm code
```
public class CustomShardingDbAlgorithm implements StandardShardingAlgorithm<Long> {
@Override
public String doSharding(Collection<String> availableTargetNames, PreciseShardingValue<Long> preciseShardingValue) {
Long shardCol = preciseShardingValue.getValue();
return null;
}
@Override
public String getType() {
return "CUSTOM_SHARD";
}
}
```
then I use navicat connect to sharding-proxy. Insert data using the SQL as follows
```
INSERT INTO `t_order` ( `order_id`, `user_id`, `status`) VALUES ( 100000 ,100000, 'test');
```
Exception occurred.
### Actual behavior
```
[ERROR] 2022-07-08 17:21:52.112 [ShardingSphere-Command-0] o.a.s.p.f.c.CommandExecutorTask - Exception occur:
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
at com.yuanian.shard.config.algorithm.CustomShardingDbAlgorithm.doSharding(CustomShardingDbAlgorithm.java:29)
at org.apache.shardingsphere.sharding.route.strategy.type.standard.StandardShardingStrategy.doSharding(StandardShardingStrategy.java:83)
at org.apache.shardingsphere.sharding.route.strategy.type.standard.StandardShardingStrategy.doSharding(StandardShardingStrategy.java:71)
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeDataSources(ShardingStandardRoutingEngine.java:218)
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.route0(ShardingStandardRoutingEngine.java:206)
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeByShardingConditionsWithCondition(ShardingStandardRoutingEngine.java:127)
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.routeByShardingConditions(ShardingStandardRoutingEngine.java:117)
at org.apache.shardingsphere.sharding.route.engine.type.standard.ShardingStandardRoutingEngine.getDataNodes(ShardingStandardRoutingEngine.java:94)
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:58)
at org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.createRouteContext(ShardingSQLRouter.java:45)
at org.apache.shardingsphere.infra.route.engine.impl.PartialSQLRouteExecutor.route(PartialSQLRouteExecutor.java:69)
at org.apache.shardingsphere.infra.route.engine.SQLRouteEngine.route(SQLRouteEngine.java:55)
at org.apache.shardingsphere.infra.context.kernel.KernelProcessor.route(KernelProcessor.java:58)
at org.apache.shardingsphere.infra.context.kernel.KernelProcessor.generateExecutionContext(KernelProcessor.java:47)
at org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine.execute(JDBCDatabaseCommunicationEngine.java:127)
at org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine.execute(JDBCDatabaseCommunicationEngine.java:73)
at org.apache.shardingsphere.proxy.backend.text.data.impl.SchemaAssignedDatabaseBackendHandler.execute(SchemaAssignedDatabaseBackendHandler.java:61)
at org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query.MySQLComQueryPacketExecutor.execute(MySQLComQueryPacketExecutor.java:103)
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.executeCommand(CommandExecutorTask.java:116)
at org.apache.shardingsphere.proxy.frontend.command.CommandExecutorTask.run(CommandExecutorTask.java:81)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
```
### Reason analyze (If you can)
I think the exception happened here:`SQLVisitorEngine# visit(ParseASTNode)`
```
public <T> T visit(final ParseASTNode parseASTNode) {
ParseTreeVisitor<T> visitor = SQLVisitorFactory.newInstance(databaseType, visitorType, SQLVisitorRule.valueOf(parseASTNode.getRootNode().getClass()), props);
T result = parseASTNode.getRootNode().accept(visitor);
if (isParseComment) {
appendSQLComments(parseASTNode, result);
}
return result;
}
```
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
server.yaml
```
mode:
type: Cluster
repository:
type: ZooKeeper
props:
namespace: governance_local
server-lists: zkserver1:2181
retryIntervalMilliseconds: 600
timeToLiveSeconds: 1500
maxRetries: 3
overwrite: false
rules:
- !AUTHORITY
users:
- root@%:root
- sharding@:sharding
provider:
type: ALL_PRIVILEGES_PERMITTED
- !TRANSACTION
defaultType: LOCAL
props:
max-connections-size-per-query: 5 # 每次查询的最大连接消耗数
kernel-executor-size: 16
proxy-frontend-flush-threshold: 128
proxy-opentracing-enabled: false
proxy-hint-enabled: false
sql-show: false
check-table-metadata-enabled: false
show-process-list-enabled: false
proxy-backend-query-fetch-size: -1
check-duplicate-table-enabled: false
proxy-frontend-executor-size: 0
proxy-backend-executor-suitable: OLAP
proxy-frontend-max-connections: 0
sql-federation-enabled: false
proxy-backend-driver-type: JDBC
proxy-mysql-default-version: 5.6.48
```
### Example codes for reproduce this issue (such as a github link).
--
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.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] TeslaCN commented on issue #18961: 5.1.2-ShardingProxy java.lang.Integer cannot be cast to java.lang.Long
Posted by GitBox <gi...@apache.org>.
TeslaCN commented on issue #18961:
URL: https://github.com/apache/shardingsphere/issues/18961#issuecomment-1179961901
> By the way, Can you provide some articles or blogs about async-profile.
Please refer to https://github.com/jvm-profiling-tools/async-profiler
--
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] chenliang7558 commented on issue #18961: 5.1.2-ShardingProxy java.lang.Integer cannot be cast to java.lang.Long
Posted by GitBox <gi...@apache.org>.
chenliang7558 commented on issue #18961:
URL: https://github.com/apache/shardingsphere/issues/18961#issuecomment-1179960472
By the way, Can you provide some articles or blogs about async-profile.
--
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] chenliang7558 commented on issue #18961: 5.1.2-ShardingProxy java.lang.Integer cannot be cast to java.lang.Long
Posted by GitBox <gi...@apache.org>.
chenliang7558 commented on issue #18961:
URL: https://github.com/apache/shardingsphere/issues/18961#issuecomment-1179836641
Can someone help me look at this problem?
I think it's the problem of AST syntax parsing.
--
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] TeslaCN commented on issue #18961: 5.1.2-ShardingProxy java.lang.Integer cannot be cast to java.lang.Long
Posted by GitBox <gi...@apache.org>.
TeslaCN commented on issue #18961:
URL: https://github.com/apache/shardingsphere/issues/18961#issuecomment-1179908464
Hi @chenliang7558
I found that the type depends on the value:
```sql
INSERT INTO `t_order` ( `order_id`, `user_id`, `status`) VALUES ( 100000 ,100000, 'test');
```
<img width="1424" alt="image" src="https://user-images.githubusercontent.com/20503072/178179100-373481fe-ee41-4b38-80fb-cce33907a8ef.png">
```sql
INSERT INTO `t_order` ( `order_id`, `user_id`, `status`) VALUES ( 2147483648 ,100000, 'test');
```
<img width="1396" alt="image" src="https://user-images.githubusercontent.com/20503072/178179250-9ae113ff-7e09-455c-bd0c-157aef599167.png">
Column's type is not available for SQL parser, so you may use `Number` or check the type on your own.
You may refer to our `ModShardingAlgorithm`.
--
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] TeslaCN commented on issue #18961: 5.1.2-ShardingProxy java.lang.Integer cannot be cast to java.lang.Long
Posted by GitBox <gi...@apache.org>.
TeslaCN commented on issue #18961:
URL: https://github.com/apache/shardingsphere/issues/18961#issuecomment-1179961747
> thank you so much @TeslaCN If I want to express number with explicit generics, I can only use String?
You may use `Number`.
--
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] chenliang7558 commented on issue #18961: 5.1.2-ShardingProxy java.lang.Integer cannot be cast to java.lang.Long
Posted by GitBox <gi...@apache.org>.
chenliang7558 commented on issue #18961:
URL: https://github.com/apache/shardingsphere/issues/18961#issuecomment-1179928629
thank you so much @TeslaCN
If I want to express number with explicit generics, I can only use String?
--
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] TeslaCN commented on issue #18961: 5.1.2-ShardingProxy java.lang.Integer cannot be cast to java.lang.Long
Posted by GitBox <gi...@apache.org>.
TeslaCN commented on issue #18961:
URL: https://github.com/apache/shardingsphere/issues/18961#issuecomment-1179918707
As an aside, the codes could be optimized.

--
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] TeslaCN commented on issue #18961: 5.1.2-ShardingProxy java.lang.Integer cannot be cast to java.lang.Long
Posted by GitBox <gi...@apache.org>.
TeslaCN commented on issue #18961:
URL: https://github.com/apache/shardingsphere/issues/18961#issuecomment-1179912830
This issue is related to code here:
https://github.com/apache/shardingsphere/blob/8288ed33f59f40f9c1ddd3398d91ac680a66f5bd/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/value/literal/impl/NumberLiteralValue.java#L47-L56
--
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] chenliang7558 commented on issue #18961: 5.1.2-ShardingProxy java.lang.Integer cannot be cast to java.lang.Long
Posted by GitBox <gi...@apache.org>.
chenliang7558 commented on issue #18961:
URL: https://github.com/apache/shardingsphere/issues/18961#issuecomment-1179962701
All right, thank you so much!
--
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] chenliang7558 closed issue #18961: 5.1.2-ShardingProxy java.lang.Integer cannot be cast to java.lang.Long
Posted by GitBox <gi...@apache.org>.
chenliang7558 closed issue #18961: 5.1.2-ShardingProxy java.lang.Integer cannot be cast to java.lang.Long
URL: https://github.com/apache/shardingsphere/issues/18961
--
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