sccc803 opened a new issue #13953:
URL: https://github.com/apache/shardingsphere/issues/13953
### Which version of ShardingSphere did you use?
Master branch.
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
ShardingSphere-Proxy
### Expected behavior
Here is a logic table called t_order, show create table:
CREATE TABLE `t_order` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`order_id` bigint(20) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
Insert a record:
``` sql
INSERT INTO t_order (order_id) VALUES (1);
```
Then execute JDBC code below,
``` java
Connection conn = DriverManager.getConnection("jdbc:mysql://xxx",
"username", "password");
PreparedStatement pstmt = conn.prepareStatement("select * from t_order");
return pstmt.executeQuery();
```
It supposed to return the correct ResultSet.
### Actual behavior
An exception has been thrown:
```
java.sql.SQLException: Unknown exception: [java.math.BigInteger cannot be
cast to java.lang.Long]
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3978)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3914)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871)
at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1999)
at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:3403)
at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:471)
at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:3115)
at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:2344)
at
com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1373)
at
com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:788)
at
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2011)
at PrepareStatementTest.selectAll(PrepareStatementTest.java:34)
at PrepareStatementTest.main(PrepareStatementTest.java:57)
```
### Reason analyze (If you can)
Mysql driver converts unsigned bigint to BigInter in java when using
PrepareStatement. And Proxy do not resolve BigInteger write into ByteBuf.
```java
public final class MySQLInt8BinaryProtocolValue implements
MySQLBinaryProtocolValue {
@Override
public Object read(final MySQLPacketPayload payload) {
return payload.readInt8();
}
@Override
public void write(final MySQLPacketPayload payload, final Object value) {
if (value instanceof BigDecimal) {
payload.writeInt8(((BigDecimal) value).longValue());
} else if (value instanceof Integer) {
payload.writeInt8(((Integer) value).longValue());
} else {
payload.writeInt8((Long) value);
}
// Do not resolve type of BigInteger.
}
}
```
### Steps to reproduce the behavior, such as: SQL to execute, sharding rule
configuration, when exception occur etc.
1. Set configuration of Proxy:
```yaml
schemaName: sharding_db
dataSources:
ds_0:
url: jdbc:mysql://127.0.0.1:3306/test?serverTimezone=UTC&useSSL=false
username: username
password: password
connectionTimeoutMilliseconds: 30000
idleTimeoutMilliseconds: 60000
maxLifetimeMilliseconds: 1800000
maxPoolSize: 50
minPoolSize: 1
rules:
- !SHARDING
tables:
t_order:
actualDataNodes: ds_0.t_order_${0..1}
tableStrategy:
standard:
shardingColumn: order_id
shardingAlgorithmName: t_order_inline
keyGenerateStrategy:
column: order_id
keyGeneratorName: snowflake
shardingAlgorithms:
t_order_inline:
type: INLINE
props:
algorithm-expression: t_order_${order_id % 2}
keyGenerators:
snowflake:
type: SNOWFLAKE
props:
worker-id: 123
```
2. Create t_order_0 , t_order_1 on ds_0:
``` sql
CREATE TABLE `t_order` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`order_id` bigint(20) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
```
3. Start up proxy, and execute insert statement:
``` sql
INSERT INTO t_order (order_id) VALUES (1);
```
4. Execute JDBC query by PrepareStamentment:
``` java
Connection conn =
DriverManager.getConnection("jdbc:mysql://127.0.0.1:3307/sharding_db?useServerPrepStmts=true&&useSSL=false",
"username", "password");
PreparedStatement pstmt = conn.prepareStatement("select * from t_order");
return pstmt.executeQuery();
```
### 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]