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

jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 612ccb5b08e Optimized the error message for database containing 
illegal characters' creation in table model
612ccb5b08e is described below

commit 612ccb5b08ef672d0ea89048f9644d904f472479
Author: Caideyipi <[email protected]>
AuthorDate: Mon Sep 23 09:49:00 2024 +0800

    Optimized the error message for database containing illegal characters' 
creation in table model
---
 .../iotdb/relational/it/schema/IoTDBDatabaseIT.java       | 13 +++++++++++--
 .../plan/execution/config/TableConfigTaskVisitor.java     | 15 +++++++++------
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseIT.java
index a357fda8fc6..d1552826872 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBDatabaseIT.java
@@ -225,10 +225,19 @@ public class IoTDBDatabaseIT {
         final Statement statement = connection.createStatement()) {
       try {
         statement.execute("create database \"````x.\"");
-        fail("create database test shouldn't succeed because it contains '.'");
+        fail("create database ````x. shouldn't succeed because it contains 
'.'");
       } catch (final SQLException e) {
         assertEquals(
-            "509: ````x. is not a legal path, because The database name shall 
not contain '.'",
+            "509: ````x. is not a legal path, because the database name can 
only contain english or chinese characters, numbers, backticks and 
underscores.",
+            e.getMessage());
+      }
+
+      try {
+        statement.execute("create database \"#\"");
+        fail("create database # shouldn't succeed because it contains illegal 
character '#'");
+      } catch (final SQLException e) {
+        assertEquals(
+            "509: # is not a legal path, because the database name can only 
contain english or chinese characters, numbers, backticks and underscores.",
             e.getMessage());
       }
 
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java
index f2d49a6594d..2f5137bc5cd 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/TableConfigTaskVisitor.java
@@ -23,6 +23,7 @@ import 
org.apache.iotdb.commons.exception.IllegalPathException;
 import org.apache.iotdb.commons.schema.table.TsTable;
 import org.apache.iotdb.commons.schema.table.column.TsTableColumnCategory;
 import org.apache.iotdb.confignode.rpc.thrift.TDatabaseSchema;
+import org.apache.iotdb.db.conf.IoTDBConfig;
 import org.apache.iotdb.db.exception.sql.SemanticException;
 import org.apache.iotdb.db.protocol.session.IClientSession;
 import org.apache.iotdb.db.queryengine.common.MPPQueryContext;
@@ -129,15 +130,17 @@ public class TableConfigTaskVisitor extends 
AstVisitor<IConfigTask, MPPQueryCont
     final String dbName = node.getDbName();
     // Check database length here
     // We need to calculate the database name without "root."
-    if (dbName.contains(PATH_SEPARATOR) || dbName.length() > 
MAX_DATABASE_NAME_LENGTH) {
+    if (dbName.contains(PATH_SEPARATOR)
+        || !IoTDBConfig.STORAGE_GROUP_PATTERN.matcher(dbName).matches()
+        || dbName.length() > MAX_DATABASE_NAME_LENGTH) {
       throw new SemanticException(
           new IllegalPathException(
-              node.getDbName(),
-              dbName.contains(PATH_SEPARATOR)
-                  ? "The database name shall not contain '.'"
-                  : "the length of database name shall not exceed " + 
MAX_DATABASE_NAME_LENGTH));
+              dbName,
+              dbName.length() > MAX_DATABASE_NAME_LENGTH
+                  ? "the length of database name shall not exceed " + 
MAX_DATABASE_NAME_LENGTH
+                  : "the database name can only contain english or chinese 
characters, numbers, backticks and underscores."));
     }
-    schema.setName(ROOT + PATH_SEPARATOR_CHAR + node.getDbName());
+    schema.setName(ROOT + PATH_SEPARATOR_CHAR + dbName);
 
     for (final Property property : node.getProperties()) {
       final String key = 
property.getName().getValue().toLowerCase(Locale.ENGLISH);

Reply via email to