This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 68c10080ae1 fix data node suffix pattern(#19423) (#19767)
68c10080ae1 is described below
commit 68c10080ae14197056a82506956228ab8d86e0f6
Author: wuleihao <[email protected]>
AuthorDate: Wed Aug 3 14:00:34 2022 +0800
fix data node suffix pattern(#19423) (#19767)
* fix data node suffix pattern(#19423)
* add test case about new data node suffix pattern
* fix code style
* fix code style
Co-authored-by: 吴雷浩 <[email protected]>
---
.../shardingsphere/sharding/rule/TableRule.java | 2 +-
.../sharding/rule/TableRuleTest.java | 25 +++++++++++++++++++++-
2 files changed, 25 insertions(+), 2 deletions(-)
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 d6fb83a9927..66493cad145 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
@@ -56,7 +56,7 @@ import java.util.stream.Collectors;
@ToString(exclude = {"dataNodeIndexMap", "actualTables", "actualTablePrefix",
"actualDataSourceNames", "dataSourceDataNode", "tableDataNode"})
public final class TableRule {
- private static final Pattern DATA_NODE_SUFFIX_PATTERN =
Pattern.compile("\\d+$");
+ private static final Pattern DATA_NODE_SUFFIX_PATTERN =
Pattern.compile("(\\d+[\\-_]){0,}(\\d+$)");
private static final char DEFAULT_PADDING_CHAR = '0';
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 3fe3d7c8d69..b8668d1fd4d 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
@@ -37,8 +37,11 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.Set;
+import java.util.regex.Pattern;
import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -206,7 +209,27 @@ public final class TableRuleTest {
assertTrue(actual.get("ds_1").contains(new DataNode("ds_1",
"tmp_t_order_1")));
assertTrue(actual.get("ds_1").contains(new DataNode("ds_1",
"tmp_t_order_3")));
}
-
+
+ @Test
+ public void assertDatNodeSuffixPattern() {
+ String regex = "(\\d+[\\-_]){0,}(\\d+$)";
+ Pattern dataNodeSuffixPattern = Pattern.compile(regex);
+ Set<String> set = new LinkedHashSet<>();
+ set.add("t_order_1");
+ set.add("t_order_2_0");
+ set.add("t_order_3-0_0");
+ set.add("t_order_4-0_0-0");
+ set.add("t_order_5_0-0-0_0");
+ set.add("t_order_6_0_0-0_0-0");
+ set.add("t_order_7_0_0-0_0_0-0");
+ set.add("t_order_8_0_0-0_0_0-0_0");
+ set.add("t_order_9_0_0-0_0_0-0_0-0");
+ set.add("t_order_10_0_0-0_0_0-0-0-0_0");
+ set.forEach(s -> {
+ assertEquals("t_order_",
dataNodeSuffixPattern.matcher(s).replaceAll(""));
+ });
+ }
+
private ModShardingAlgorithm createModShardingAlgorithm() {
ModShardingAlgorithm result = new ModShardingAlgorithm();
Properties props = new Properties();