From 8c669cc16e713c416e1f0f01a6ffc44329fe313c Mon Sep 17 00:00:00 2001 From: Chen YZ Date: Tue, 4 Jun 2024 12:22:58 +0800 Subject: [PATCH 1/2] done --- .../db/it/schema/IoTDBCreateTimeseriesIT.java | 31 +++++++++++++++++++ .../queryengine/plan/parser/ASTVisitor.java | 3 ++ 2 files changed, 34 insertions(+) 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 fe9832422c0b1..9bb22ea599a42 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 @@ public void testQueryDataFromTimeSeriesWithoutData() { } 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/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 f2d37f06d75a1..c0141de41f63d 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 @@ private TSDataType parseDataTypeAttribute(IoTDBSqlParser.AttributeClausesContext 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)); } From d2e774c852b2c52162748c4c094c144f21b71f16 Mon Sep 17 00:00:00 2001 From: Chen YZ Date: Tue, 4 Jun 2024 13:28:35 +0800 Subject: [PATCH 2/2] fix IT --- .../org/apache/iotdb/db/it/selectinto/IoTDBSelectIntoIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 0f8ca0df38a93..fc3f71df0aee3 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",