The same sharding rule, sharding-proxy 3.0.0 can query the data, sharding-proxy 3.1.0 can not query the data.
sharding-proxy config like this:
trans_router:
actualDataNodes: ds_0.trans_router_000${0..1},ds_1.trans_router_000${2..3}
databaseStrategy:
inline:
shardingColumn: trans_no
algorithmExpression: ds_${(trans_no.hashCode().abs() % 4).intdiv(2)}
tableStrategy:
inline:
shardingColumn: trans_no
algorithmExpression: trans_router_${"000" + (trans_no.hashCode().abs() % 4)}
sql statement is as follows:
select * from trans_router where trans_no = '63201810160018204385';
If we use sharding-proxy version 3.0.0, we can query the results. If we use sharding-proxy version 3.1.0, we can't query the result. I debug the sharding-proxy 3.1.0 program and found the error in the AntlrParsingEngine class. Parsing the sql condition value in the AntlrParsingEngine class parse method is -1, the correct value should be 63201810160018204385.
code show as below:
SQLStatement result = fillerEngine.fill(sqlSegments, ast.getRule());
already fixed it ,please view #1784
I modified the OrConditionFiller.java code according to #1784, but I still can't query the data with this sql. I debug the program under the breakpoint. The value parsed by the sql condition is still -1. When the program enter the buildExpression method of the OrConditionFiller class, The value of the expressionSegment variable is already -1.
OrConditionFiller.java
private com.google.common.base.Optional<SQLExpression> buildExpression(final SelectStatement selectStatement, final ExpressionSegment expressionSegment, final String sql,
final ShardingRule shardingRule, final ShardingTableMetaData shardingTableMetaData) {
if (!(expressionSegment instanceof CommonExpressionSegment)) {
new ExpressionFiller().fill(expressionSegment, selectStatement, sql, shardingRule, shardingTableMetaData);
return com.google.common.base.Optional.absent();
}
CommonExpressionSegment commonExpressionSegment = (CommonExpressionSegment) expressionSegment;
if (-1 < commonExpressionSegment.getIndex()) {
return com.google.common.base.Optional.<SQLExpression>of(new SQLPlaceholderExpression(commonExpressionSegment.getIndex()));
}
if (null != commonExpressionSegment.getValue()) {
return com.google.common.base.Optional.<SQLExpression>of(new SQLNumberExpression(commonExpressionSegment.getValue()));
}
//String expression = sql.substring(commonExpressionSegment.getStartPosition(), commonExpressionSegment.getEndPosition() + 1);
//return Optional.<SQLExpression>of(new SQLTextExpression(expression));
if(commonExpressionSegment.isText()) {
return Optional.<SQLExpression>of(new SQLTextExpression(sql.substring(commonExpressionSegment.getStartPosition() + 1, commonExpressionSegment.getEndPosition())));
}
return Optional.<SQLExpression>of(new SQLTextExpression(sql.substring(commonExpressionSegment.getStartPosition(), commonExpressionSegment.getEndPosition() + 1)));
}
duplicated with #1784
thanks a lot, I pulled the 3.1.0 development branch down and the problem has been solved. But I found that using the 3.1.0 development branch, navicat can't connect to the sharding-proxy service, you must use jdbc to connect. The navicat connection sharding-proxy will report an error: the current logic schema is null. This is due to the non-empty check of the logical library in the BackendConnection class. If you can't connect to the sharding-proxy service with the mysql client tool, the user experience is not good. When do you plan to release the 3.1.0 version again?