For English only, other languages will not accept.
Before report a bug, make sure you have:
Please pay attention on issues you submitted, because we maybe need more details.
If no response more than 7 days and we cannot reproduce it on current information, we will close it.
Please answer these questions before submitting your issue. Thanks!
4.0.0-RC2-SNAPSHOT(clone from dev branch)
Sharding-JDBC
sql execute success
Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
my code below:
public List
String sql = "select id,name,age,email from user limit ?,? ";
Object[] params = new Object[] {begin, end};
List
return userList;
}
public List
String sql = "select id,name,age,email from user limit ?,? ";
Object[] params = new Object[] {begin, end};
List
return userList;
}
first, call findUsersByPageIntType method, it's ok
but call findUsersByPageLongType method there was an error -> Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
1.application.properties
spring.shardingsphere.datasource.names=ds0
spring.shardingsphere.datasource.ds0.type=com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.ds0.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.ds0.jdbc-url=jdbc:mysql://127.0.0.1:3306/ttx_util?useUnicode=true&useSSL=false&characterEncoding=utf8
spring.shardingsphere.datasource.ds0.username=test
spring.shardingsphere.datasource.ds0.password=test
spring.shardingsphere.sharding.tables.user.actual-data-nodes=ds0.user_$->{0..1}
spring.shardingsphere.sharding.tables.user.table-strategy.inline.sharding-column=erp_id
spring.shardingsphere.sharding.tables.user.table-strategy.inline.algorithm-expression=user_$->{erp_id % 2}
spring.shardingsphere.sharding.tables.user.key-generator.column=id
spring.shardingsphere.sharding.tables.user.key-generator.type=SNOWFLAKE
spring.shardingsphere.props.sql.show=true
2.table create sql:
CREATE TABLE user_0 (
id bigint(20) NOT NULL COMMENT '主键ID',
erp_id int(11) NOT NULL COMMENT '分表erpId',
name varchar(30) DEFAULT NULL COMMENT '姓名',
age int(11) DEFAULT NULL COMMENT '年龄',
email varchar(50) DEFAULT NULL COMMENT '邮箱',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE user_1 (
id bigint(20) NOT NULL COMMENT '主键ID',
erp_id int(11) NOT NULL COMMENT '分表erpId',
name varchar(30) DEFAULT NULL COMMENT '姓名',
age int(11) DEFAULT NULL COMMENT '年龄',
email varchar(50) DEFAULT NULL COMMENT '邮箱',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
The code below shows that Long is not supported
May I ask why you need to use Long for limit ?
Code of org.apache.shardingsphere.core.optimize.sharding.segment.select.pagination.Pagination
private final int actualOffset;
private final Integer actualRowCount;
public Pagination(final PaginationValueSegment offsetSegment, final PaginationValueSegment rowCountSegment, final List<Object> parameters) {
hasPagination = null != offsetSegment || null != rowCountSegment;
this.offsetSegment = offsetSegment;
this.rowCountSegment = rowCountSegment;
actualOffset = null == offsetSegment ? 0 : getValue(offsetSegment, parameters);
actualRowCount = null == rowCountSegment ? null : getValue(rowCountSegment, parameters);
}
private int getValue(final PaginationValueSegment paginationValueSegment, final List<Object> parameters) {
return paginationValueSegment instanceof ParameterMarkerPaginationValueSegment
?
(int) parameters.get(((ParameterMarkerPaginationValueSegment) paginationValueSegment).getParameterIndex())
: ((NumberLiteralPaginationValueSegment) paginationValueSegment).getValue();
}
@hqq2023623 I used mybatis-plus as orm, its paging plugin used long type parameter as limit parameter.
i just write the demo code to verify this problem
I test in mysql 5.7.21, offset and row count of limit can be over INTEGER.MAX.
sql> select * from t_order limit 0, 9999999999
[2019-09-03 09:21:48] 5 rows retrieved starting from 1 in 28ms (execution: 17ms, fetching: 11ms)
sql> select * from t_order limit 9999999999, 9999999999
[2019-09-03 09:22:27] 0 rows retrieved in 37ms (execution: 21ms, fetching: 16ms)
So, I think Pagination in ShardingSphere should use type Long instead of Integer for offset and row count to solve this exception.
I had the same problem
I agree with KomachiSion, can i submit a PR ?
@sunbufu Welcome
I meet the same problem. 4.0.0-RC3 version could fix it? when does 4.0.0-RC3 come?
Yes, you can clone dev branch and try with 4.0.0-RC3-SNAPSHOT again. And the new version is coming, please just wait.
Most helpful comment
I test in mysql 5.7.21, offset and row count of limit can be over INTEGER.MAX.
So, I think
Paginationin ShardingSphere should use type Long instead of Integer for offset and row count to solve this exception.