This is an automated email from the ASF dual-hosted git repository.

zhangliang 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 99f61289d65 Add NodePathPattern.QUALIFIED_IDENTIFIER (#34760)
99f61289d65 is described below

commit 99f61289d6538dd14f54a9d4a584e55c83c53dbc
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Feb 23 17:40:40 2025 +0800

    Add NodePathPattern.QUALIFIED_IDENTIFIER (#34760)
    
    * Add NodePathPattern.QUALIFIED_IDENTIFIER
    
    * Add NodePathPattern.QUALIFIED_IDENTIFIER
    
    * Add NodePathPattern.QUALIFIED_IDENTIFIER
---
 .../mode/node/path/NodePathPattern.java            |  7 ++-
 .../node/storage/QualifiedDataSourceNodePath.java  |  3 +-
 .../mode/node/path/NodePathPatternTest.java        | 50 ++++++++++++++++++++++
 3 files changed, 58 insertions(+), 2 deletions(-)

diff --git 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/NodePathPattern.java
 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/NodePathPattern.java
index 2eb0686d35a..57e55f7a179 100644
--- 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/NodePathPattern.java
+++ 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/NodePathPattern.java
@@ -29,5 +29,10 @@ public final class NodePathPattern {
     /**
      * Identifier pattern.
      */
-    public static final String IDENTIFIER = "([\\w\\-]+)";
+    public static final String IDENTIFIER = "([\\w-]+)";
+    
+    /**
+     * Qualified identifier pattern.
+     */
+    public static final String QUALIFIED_IDENTIFIER = "([\\w.-]+)";
 }
diff --git 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/storage/QualifiedDataSourceNodePath.java
 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/storage/QualifiedDataSourceNodePath.java
index e7eb7fa6ddd..0360fc1ab97 100644
--- 
a/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/storage/QualifiedDataSourceNodePath.java
+++ 
b/mode/node/src/main/java/org/apache/shardingsphere/mode/node/path/node/storage/QualifiedDataSourceNodePath.java
@@ -22,6 +22,7 @@ import lombok.RequiredArgsConstructor;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource;
 import org.apache.shardingsphere.mode.node.path.NodePath;
 import org.apache.shardingsphere.mode.node.path.NodePathEntity;
+import org.apache.shardingsphere.mode.node.path.NodePathPattern;
 import org.apache.shardingsphere.mode.node.path.NodePathSearchCriteria;
 
 /**
@@ -44,6 +45,6 @@ public final class QualifiedDataSourceNodePath implements 
NodePath {
      * @return created search criteria
      */
     public static NodePathSearchCriteria 
createQualifiedDataSourceSearchCriteria() {
-        return new NodePathSearchCriteria(new 
QualifiedDataSourceNodePath("(\\S+)"), false, false, 1);
+        return new NodePathSearchCriteria(new 
QualifiedDataSourceNodePath(NodePathPattern.QUALIFIED_IDENTIFIER), false, 
false, 1);
     }
 }
diff --git 
a/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/NodePathPatternTest.java
 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/NodePathPatternTest.java
new file mode 100644
index 00000000000..e5360b9fd48
--- /dev/null
+++ 
b/mode/node/src/test/java/org/apache/shardingsphere/mode/node/path/NodePathPatternTest.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.node.path;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.regex.Pattern;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class NodePathPatternTest {
+    
+    @Test
+    void assertIdentifier() {
+        Pattern pattern = Pattern.compile(NodePathPattern.IDENTIFIER);
+        assertTrue(pattern.matcher("foo").matches());
+        assertTrue(pattern.matcher("foo1").matches());
+        assertTrue(pattern.matcher("foo_bar").matches());
+        assertTrue(pattern.matcher("foo-bar").matches());
+        assertFalse(pattern.matcher("foo.bar").matches());
+        assertFalse(pattern.matcher("#foo").matches());
+    }
+    
+    @Test
+    void assertQualifiedIdentifier() {
+        Pattern pattern = 
Pattern.compile(NodePathPattern.QUALIFIED_IDENTIFIER);
+        assertTrue(pattern.matcher("foo").matches());
+        assertTrue(pattern.matcher("foo1").matches());
+        assertTrue(pattern.matcher("foo_bar").matches());
+        assertTrue(pattern.matcher("foo-bar").matches());
+        assertTrue(pattern.matcher("foo.bar").matches());
+        assertFalse(pattern.matcher("#foo").matches());
+    }
+}

Reply via email to