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

jiangtian 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 36dadf5d965 Upper case data type from SQL statement, and add a 
validation for non exist data type. (#17057)
36dadf5d965 is described below

commit 36dadf5d965edcb2b36e62ef28ff914a5327997e
Author: libo <[email protected]>
AuthorDate: Wed Jan 21 18:43:20 2026 +0800

    Upper case data type from SQL statement, and add a validation for non exist 
data type. (#17057)
---
 .../db/it/schema/IoTDBAlterTimeSeriesTypeIT.java   | 16 +++++++++++++
 .../db/queryengine/plan/parser/ASTVisitor.java     | 27 +++++++++++++++-------
 2 files changed, 35 insertions(+), 8 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBAlterTimeSeriesTypeIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBAlterTimeSeriesTypeIT.java
index 3745f832d34..f7d12f10b8f 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBAlterTimeSeriesTypeIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBAlterTimeSeriesTypeIT.java
@@ -46,6 +46,7 @@ import org.apache.tsfile.write.schema.MeasurementSchema;
 import org.apache.tsfile.write.v4.TsFileTreeWriter;
 import org.apache.tsfile.write.v4.TsFileTreeWriterBuilder;
 import org.junit.AfterClass;
+import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -2733,4 +2734,19 @@ public class IoTDBAlterTimeSeriesTypeIT {
     assertEquals(true, SchemaUtils.isUsingSameColumn(TSDataType.STRING, 
TSDataType.BLOB));
     assertEquals(true, SchemaUtils.isUsingSameColumn(TSDataType.STRING, 
TSDataType.TEXT));
   }
+
+  @Test
+  public void testAlterIllegalDataType() {
+    try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
+      session.executeNonQueryStatement("CREATE TIMESERIES " + database + 
".illegal.s1 blob");
+      session.executeNonQueryStatement(
+          "ALTER TIMESERIES " + database + ".illegal.s1 SET DATA TYPE text");
+      session.executeNonQueryStatement(
+          "ALTER TIMESERIES " + database + ".illegal.s1 SET DATA TYPE star");
+    } catch (StatementExecutionException e) {
+      Assert.assertEquals("701: Unsupported datatype: STAR", e.getMessage());
+    } catch (IoTDBConnectionException e) {
+      throw new RuntimeException(e);
+    }
+  }
 }
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 8dbd79f8898..70325257b08 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
@@ -353,6 +353,8 @@ public class ASTVisitor extends 
IoTDBSqlParserBaseVisitor<Statement> {
       Pattern.compile(NODE_NAME_IN_INTO_PATH_MATCHER);
 
   private static final String IGNORENULL = "IgnoreNull";
+  public static final String UNSUPPORTED_DATATYPE_MSG = "Unsupported datatype: 
%s";
+  public static final String INCORRECT_DATA_TYPE_MSG = "Incorrect Data type";
   private ZoneId zoneId;
 
   private boolean useWildcard = false;
@@ -460,7 +462,7 @@ public class ASTVisitor extends 
IoTDBSqlParserBaseVisitor<Statement> {
         
createTimeSeriesStatement.setDataType(TSDataType.valueOf(datatypeString));
         props.remove(IoTDBConstant.COLUMN_TIMESERIES_DATATYPE.toLowerCase());
       } catch (Exception e) {
-        throw new SemanticException(String.format("Unsupported datatype: %s", 
datatypeString));
+        throw new SemanticException(String.format(UNSUPPORTED_DATATYPE_MSG, 
datatypeString));
       }
     }
     if (createTimeSeriesStatement.getDataType() == null) {
@@ -685,15 +687,24 @@ public class ASTVisitor extends 
IoTDBSqlParserBaseVisitor<Statement> {
 
   private TSDataType 
parseDataTypeAttribute(IoTDBSqlParser.AttributeValueContext ctx) {
     if (ctx == null) {
-      throw new SemanticException("Incorrect Data type");
+      throw new SemanticException(INCORRECT_DATA_TYPE_MSG);
     }
 
     String dataTypeString = parseAttributeValue(ctx);
-    TSDataType dataType = TSDataType.valueOf(dataTypeString);
-    if (TSDataType.UNKNOWN.equals(dataType) || 
TSDataType.VECTOR.equals(dataType)) {
-      throw new SemanticException(String.format("Unsupported datatype: %s", 
dataTypeString));
+    if (dataTypeString == null || dataTypeString.isEmpty()) {
+      throw new SemanticException(INCORRECT_DATA_TYPE_MSG);
+    }
+
+    dataTypeString = dataTypeString.trim().toUpperCase();
+    try {
+      TSDataType dataType = TSDataType.valueOf(dataTypeString);
+      if (TSDataType.UNKNOWN.equals(dataType) || 
TSDataType.VECTOR.equals(dataType)) {
+        throw new SemanticException(String.format(UNSUPPORTED_DATATYPE_MSG, 
dataTypeString));
+      }
+      return dataType;
+    } catch (IllegalArgumentException e) {
+      throw new SemanticException(String.format(UNSUPPORTED_DATATYPE_MSG, 
dataTypeString));
     }
-    return dataType;
   }
 
   @Override
@@ -4036,10 +4047,10 @@ public class ASTVisitor extends 
IoTDBSqlParserBaseVisitor<Statement> {
       try {
         dataType = TSDataType.valueOf(dataTypeString);
         if (TSDataType.UNKNOWN.equals(dataType) || 
TSDataType.VECTOR.equals(dataType)) {
-          throw new SemanticException(String.format("Unsupported datatype: 
%s", dataTypeString));
+          throw new SemanticException(String.format(UNSUPPORTED_DATATYPE_MSG, 
dataTypeString));
         }
       } catch (Exception e) {
-        throw new SemanticException(String.format("Unsupported datatype: %s", 
dataTypeString));
+        throw new SemanticException(String.format(UNSUPPORTED_DATATYPE_MSG, 
dataTypeString));
       }
     }
     return dataType;

Reply via email to