This is an automated email from the ASF dual-hosted git repository.
totalo pushed a commit to branch 5.2.0-release
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/5.2.0-release by this push:
new deca3a6ef45 Fix binding table check exception when sharding table ends
with number (#20784)
deca3a6ef45 is described below
commit deca3a6ef454bf7c6745d9d2b9c6cbf33492d9ed
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Mon Sep 5 11:49:47 2022 +0800
Fix binding table check exception when sharding table ends with number
(#20784)
---
.../org/apache/shardingsphere/sharding/rule/TableRule.java | 4 +++-
.../org/apache/shardingsphere/sharding/rule/TableRuleTest.java | 10 ++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
index 89e7a942b38..27c8b280391 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/rule/TableRule.java
@@ -145,7 +145,9 @@ public final class TableRule {
}
private DataNodeInfo createTableDataNode(final Collection<DataNode>
actualDataNodes) {
- String prefix =
DATA_NODE_SUFFIX_PATTERN.matcher(actualDataNodes.iterator().next().getTableName()).replaceAll("");
+ String tableName = actualDataNodes.iterator().next().getTableName();
+ String prefix = tableName.startsWith(logicTable) ? logicTable +
DATA_NODE_SUFFIX_PATTERN.matcher(tableName.substring(logicTable.length())).replaceAll("")
+ : DATA_NODE_SUFFIX_PATTERN.matcher(tableName).replaceAll("");
int suffixMinLength = actualDataNodes.stream().map(each ->
each.getTableName().length() -
prefix.length()).min(Comparator.comparing(Integer::intValue)).orElse(1);
return new DataNodeInfo(prefix, suffixMinLength, DEFAULT_PADDING_CHAR);
}
diff --git
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
index a37979a6599..1faf75156a6 100644
---
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
+++
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/rule/TableRuleTest.java
@@ -190,6 +190,16 @@ public final class TableRuleTest {
assertThat(actual.getSuffixMinLength(), is(3));
}
+ @Test
+ public void assertGetTableDataNodeWhenLogicTableEndWithNumber() {
+ ShardingTableRuleConfiguration shardingTableRuleConfig = new
ShardingTableRuleConfiguration("t_order0", "ds_0.t_order0_0,ds_0.t_order0_1");
+ TableRule tableRule = new TableRule(shardingTableRuleConfig,
Arrays.asList("ds_0", "ds_1"), "order_id");
+ DataNodeInfo actual = tableRule.getTableDataNode();
+ assertThat(actual.getPrefix(), is("t_order0_"));
+ assertThat(actual.getPaddingChar(), is('0'));
+ assertThat(actual.getSuffixMinLength(), is(1));
+ }
+
@Test
public void assertGetDataSourceDataNode() {
ShardingTableRuleConfiguration shardingTableRuleConfig = new
ShardingTableRuleConfiguration("t_order", "ds_0.t_order,ds_1.t_order");