You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/04/20 07:30:58 UTC

[shardingsphere] branch master updated: Fixed get schema name problem and add unit test (#16949)

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 5ffc00790d0 Fixed get schema name problem and add unit test (#16949)
5ffc00790d0 is described below

commit 5ffc00790d0d02eb6dbf225a508c87bb7150301c
Author: zhaojinchao <zh...@apache.org>
AuthorDate: Wed Apr 20 15:30:46 2022 +0800

    Fixed get schema name problem and add unit test (#16949)
---
 .../mode/metadata/persist/node/DatabaseMetaDataNode.java           | 4 ++--
 .../mode/metadata/persist/node/DatabaseMetaDataNodeTest.java       | 7 +++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/DatabaseMetaDataNode.java b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/DatabaseMetaDataNode.java
index 1cad008a270..73d703b927f 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/DatabaseMetaDataNode.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/metadata/persist/node/DatabaseMetaDataNode.java
@@ -142,9 +142,9 @@ public final class DatabaseMetaDataNode {
      * @return schema name
      */
     public static Optional<String> getSchemaName(final String configNodeFullPath) {
-        Pattern pattern = Pattern.compile(getMetaDataNodePath() + "/([\\w\\-]+)/([\\w\\-]+)" + "(/datasources|/rules|/tables)?", Pattern.CASE_INSENSITIVE);
+        Pattern pattern = Pattern.compile(getMetaDataNodePath() + "/([\\w\\-]+)/([\\w\\-]+)/([\\w\\-]+)(/tables)?", Pattern.CASE_INSENSITIVE);
         Matcher matcher = pattern.matcher(configNodeFullPath);
-        return matcher.find() ? Optional.of(matcher.group(2)) : Optional.empty();
+        return matcher.find() ? Optional.of(matcher.group(3)) : Optional.empty();
     }
     
     /**
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/node/DatabaseMetaDataNodeTest.java b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/node/DatabaseMetaDataNodeTest.java
index 972b1838c32..946da130553 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/node/DatabaseMetaDataNodeTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/metadata/persist/node/DatabaseMetaDataNodeTest.java
@@ -71,6 +71,13 @@ public class DatabaseMetaDataNodeTest {
         assertThat(actualTableName.get(), is("t_order"));
     }
     
+    @Test
+    public void assertGetSchemaName() {
+        Optional<String> actualSchemaName = DatabaseMetaDataNode.getSchemaName("/metadata/logic_db/schemas/logic_schema/tables/t_order");
+        assertTrue(actualSchemaName.isPresent());
+        assertThat(actualSchemaName.get(), is("logic_schema"));
+    }
+    
     @Test
     public void assertGetVersionBySchemaPath() {
         Optional<String> actualVersion = DatabaseMetaDataNode.getVersionByDataSourcesPath("/metadata/logic_db/versions/0/dataSources");