Sharding-jdbc get different shardingValue between version 3.1.0 and version 2.0.3 when use a string type sharding column.
Use a string sharding column , suppose the sharding column value is "abcd"; When use sharding-jdbc 3.1.0 , found sharding value pass to ShardingStrategy.doSharding() was a integer value : -1 . But use version 2.0.3 , the sharding value is original value : "abcd"。
duplicate #1754
@terrymanu I found the fix code, merge to version 3.1.0.1 . When will this version be released, does it has a certain time?
Please subscribe mail list, you can find the scheduler of release
Please subscribe mail list, you can find the scheduler of release
Thank you so much for your patience~
@terrymanu @codefairy08 I just try with version 4.0.0.M1-SNAPSHOT , also get different with version 2.0.3. version 2.0.3 get value "abcd" (4 chars), but in version 4.0.0.M1-SNAPSHOT get value "'abcd'" (6chars)。
@AlbertTao Please describe in detail, tell me where you get value "'abcd'" ?
two column value in condition are correct.the results are shown below。

Result in InlineShardingStrategy.doSharding()

pom.xml dependency
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-core</artifactId>
<version>4.0.0.M1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.9</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>
Java code
BufferedReader reader = new BufferedReader(new InputStreamReader(OrderTest.class
.getResourceAsStream("/sharding-config-order-test.yaml"), "utf-8"));
StringBuffer sb = new StringBuffer();
CharBuffer charBuffer = CharBuffer.allocate(32);
for (int count = reader.read(charBuffer); count > 0; count = reader.read(charBuffer)) {
sb.append(charBuffer.flip());
}
DataSource dataSource = YamlShardingDataSourceFactory.createDataSource(sb.toString().getBytes("utf-8"));
Connection connection = dataSource.getConnection();
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("select ts_order.* FROM ts_order where order_id='abcd'");
sharding-config-order-test.yaml config
dataSources:
ds_0: !!com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/test_d_1
username: demo4
password: demo135
filters: stat
initialSize: 2
maxActive: 80
maxWait: 5000
testOnBorrow: true
testOnReturn: true
testWhileIdle: true
ds_1: !!com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/test_d_2
username: demo4
password: demo135
filters: stat
initialSize: 2
maxActive: 80
maxWait: 5000
testOnBorrow: true
testOnReturn: true
testWhileIdle: true
shardingRule:
tables:
ts_order:
actualDataNodes: ds_${0..1}.ts_order_0${1..2}
databaseStrategy:
inline:
shardingColumn: order_id
algorithmExpression: ds_${order_id.hashCode() % 2}
tableStrategy:
inline:
shardingColumn: order_id
algorithmExpression: ts_order_0${order_id.hashCode() % 2 + 1}
thanks , i will try it again using your code
@AlbertTao this issue was fixed at 4.0.0-RC1, i use your code testing in 4.0.0-RC1 it is ok, but in 4.0.0.M1-SNAPSHOT has a wrong value , please have a try in 4.0.0-RC1.

I had test this code in 4.0.0-RC1, and get the right value !
But I am not sure whether this problem was fix by the same code as #1754. I just found the fix code also apply to version 4.0.0.M1-SNAPSHOT。
#1754 fix code

in version 4.0.0.M1-SNAPSHOT
@RequiredArgsConstructor
@Getter
@Setter
public final class CommonExpressionSegment implements ExpressionSegment {
private final int startIndex;
private final int stopIndex;
private int index = -1;
private Number value;
private boolean text;
}
This code had not be changed in version 4.0.0.RC1 .
please view code in 4.0.0.RC1, this code fixed it .

thanks so much for your reply.