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

zyk 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 b42b533f7c Fix template type check on ClusterTemplateManager (#9494)
b42b533f7c is described below

commit b42b533f7c5bef607a26f0c86cadb25f5c689641
Author: ZhaoXin <[email protected]>
AuthorDate: Sun Apr 2 00:28:01 2023 +0800

    Fix template type check on ClusterTemplateManager (#9494)
---
 .../iotdb/db/it/schema/IoTDBSchemaTemplateIT.java       | 13 +++++++++++++
 .../db/metadata/template/ClusterTemplateManager.java    | 17 +++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBSchemaTemplateIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBSchemaTemplateIT.java
index 5e194a9a21..72728e07c6 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBSchemaTemplateIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBSchemaTemplateIT.java
@@ -68,6 +68,19 @@ public class IoTDBSchemaTemplateIT extends AbstractSchemaIT {
     // test create schema template repeatedly
     try (Connection connection = EnvFactory.getEnv().getConnection();
         Statement statement = connection.createStatement()) {
+      // test datatype and encoding check
+      try {
+        statement.execute(
+            "CREATE SCHEMA TEMPLATE str1 (s1 TEXT encoding=GORILLA 
compressor=SNAPPY, s2 INT32)");
+        Assert.fail();
+      } catch (SQLException e) {
+        System.out.println(e.getMessage());
+        Assert.assertEquals(
+            TSStatusCode.CREATE_TEMPLATE_ERROR.getStatusCode()
+                + ": create template error -encoding GORILLA does not support 
TEXT",
+            e.getMessage());
+      }
+
       try {
         statement.execute(
             "CREATE SCHEMA TEMPLATE t1 (s1 INT64 encoding=RLE 
compressor=SNAPPY, s2 INT32)");
diff --git 
a/server/src/main/java/org/apache/iotdb/db/metadata/template/ClusterTemplateManager.java
 
b/server/src/main/java/org/apache/iotdb/db/metadata/template/ClusterTemplateManager.java
index 79016e3e11..2af16c8e74 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/metadata/template/ClusterTemplateManager.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/metadata/template/ClusterTemplateManager.java
@@ -25,6 +25,7 @@ import 
org.apache.iotdb.commons.client.exception.ClientManagerException;
 import org.apache.iotdb.commons.consensus.ConfigRegionId;
 import org.apache.iotdb.commons.exception.IllegalPathException;
 import org.apache.iotdb.commons.exception.IoTDBException;
+import org.apache.iotdb.commons.exception.MetadataException;
 import org.apache.iotdb.commons.path.PartialPath;
 import org.apache.iotdb.commons.utils.TestOnly;
 import org.apache.iotdb.confignode.rpc.thrift.TCreateSchemaTemplateReq;
@@ -36,7 +37,10 @@ import org.apache.iotdb.db.client.ConfigNodeClient;
 import org.apache.iotdb.db.client.ConfigNodeClientManager;
 import org.apache.iotdb.db.client.ConfigNodeInfo;
 import 
org.apache.iotdb.db.mpp.plan.statement.metadata.template.CreateSchemaTemplateStatement;
+import org.apache.iotdb.db.utils.SchemaUtils;
 import org.apache.iotdb.rpc.TSStatusCode;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
 import org.apache.iotdb.tsfile.utils.Pair;
 
 import org.apache.thrift.TException;
@@ -87,6 +91,13 @@ public class ClusterTemplateManager implements 
ITemplateManager {
     TCreateSchemaTemplateReq req = 
constructTCreateSchemaTemplateReq(statement);
     try (ConfigNodeClient configNodeClient =
         
CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) {
+      // Guardian statements for validity of datatype and encoding
+      List<TSDataType> dataTypes = statement.getDataTypes();
+      List<TSEncoding> encodings = statement.getEncodings();
+      for (int i = 0; i < dataTypes.size(); i++) {
+        SchemaUtils.checkDataTypeWithEncoding(dataTypes.get(i), 
encodings.get(i));
+      }
+
       // Send request to some API server
       TSStatus tsStatus = configNodeClient.createSchemaTemplate(req);
       // Get response or throw exception
@@ -97,6 +108,12 @@ public class ClusterTemplateManager implements 
ITemplateManager {
             tsStatus);
       }
       return tsStatus;
+    } catch (MetadataException e) {
+      throw new RuntimeException(
+          new IoTDBException(
+              "create template error -" + e.getMessage(),
+              e,
+              TSStatusCode.CREATE_TEMPLATE_ERROR.getStatusCode()));
     } catch (ClientManagerException | TException e) {
       throw new RuntimeException(
           new IoTDBException(

Reply via email to