Optimize error message when creating unsupported data type (#12650)
Optimize error message when creating unsupported data type
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 fe98324..9bb22ea 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.util.HashSet;
import java.util.Set;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail;
/**
@@ -264,4 +265,34 @@
}
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 0f8ca0d..fc3f71d 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 @@
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 f2d37f0..c0141de 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 @@
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));
}