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

chenyz 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 ec4fc5b6b00 Optimize error message when creating unsupported data type 
(#12650)
ec4fc5b6b00 is described below

commit ec4fc5b6b00533eeeb82d40942d303c6f8beca1d
Author: Chen YZ <[email protected]>
AuthorDate: Tue Jun 4 17:22:23 2024 +0800

    Optimize error message when creating unsupported data type (#12650)
    
    Optimize error message when creating unsupported data type
---
 .../db/it/schema/IoTDBCreateTimeseriesIT.java      | 31 ++++++++++++++++++++++
 .../iotdb/db/it/selectinto/IoTDBSelectIntoIT.java  |  2 +-
 .../db/queryengine/plan/parser/ASTVisitor.java     |  3 +++
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBCreateTimeseriesIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBCreateTimeseriesIT.java
index fe9832422c0..9bb22ea599a 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBCreateTimeseriesIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBCreateTimeseriesIT.java
@@ -38,6 +38,7 @@ import java.sql.Statement;
 import java.util.HashSet;
 import java.util.Set;
 
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.fail;
 
 /**
@@ -264,4 +265,34 @@ public class IoTDBCreateTimeseriesIT extends 
AbstractSchemaIT {
     }
     Assert.assertEquals(0, cnt);
   }
+
+  @Test
+  public void testIllegalInput() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute("create timeseries root.sg2.d.s1 with datatype=INT64");
+      assertThrows(
+          "Unsupported datatype: UNKNOWN",
+          SQLException.class,
+          () -> statement.execute("create timeseries root.sg2.d.s1 with 
datatype=UNKNOWN"));
+      assertThrows(
+          "Unsupported datatype: VECTOR",
+          SQLException.class,
+          () -> statement.execute("create timeseries root.sg2.d.s1 with 
datatype=VECTOR"));
+      assertThrows(
+          "Unsupported datatype: YES",
+          SQLException.class,
+          () -> statement.execute("create timeseries root.sg2.d.s1 with 
datatype=YES"));
+      assertThrows(
+          "Unsupported datatype: UNKNOWN",
+          SQLException.class,
+          () -> statement.execute("create device template t1 (s1 UNKNOWN, s2 
boolean)"));
+      assertThrows(
+          "Unsupported datatype: VECTOR",
+          SQLException.class,
+          () -> statement.execute("create device template t1 (s1 VECTOR, s2 
boolean)"));
+    } catch (SQLException ignored) {
+      fail();
+    }
+  }
 }
diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/selectinto/IoTDBSelectIntoIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/selectinto/IoTDBSelectIntoIT.java
index 0f8ca0df38a..fc3f71df0ae 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/selectinto/IoTDBSelectIntoIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/selectinto/IoTDBSelectIntoIT.java
@@ -91,7 +91,7 @@ public class IoTDBSelectIntoIT {
     SELECT_INTO_SQL_LIST.add("CREATE DATABASE root.sg_type");
     for (int deviceId = 0; deviceId < 6; deviceId++) {
       for (TSDataType dataType : TSDataType.values()) {
-        if (!dataType.equals(TSDataType.VECTOR)) {
+        if (!dataType.equals(TSDataType.VECTOR) && 
!dataType.equals(TSDataType.UNKNOWN)) {
           SELECT_INTO_SQL_LIST.add(
               String.format(
                   "CREATE TIMESERIES root.sg_type.d_%d.s_%s %s",
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
index f2d37f06d75..c0141de41f6 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java
@@ -3554,6 +3554,9 @@ public class ASTVisitor extends 
IoTDBSqlParserBaseVisitor<Statement> {
       String dataTypeString = ctx.dataType.getText().toUpperCase();
       try {
         dataType = TSDataType.valueOf(dataTypeString);
+        if (TSDataType.UNKNOWN.equals(dataType) || 
TSDataType.VECTOR.equals(dataType)) {
+          throw new SemanticException(String.format("Unsupported datatype: 
%s", dataTypeString));
+        }
       } catch (Exception e) {
         throw new SemanticException(String.format("Unsupported datatype: %s", 
dataTypeString));
       }

Reply via email to