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

haonan 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 4e72d07de9b Featrue add insertRecords and insertTablets to the rest v2 
service for data type verification (#11708)
4e72d07de9b is described below

commit 4e72d07de9b974c783239179149fc9539bfc17c5
Author: CloudWise-Lukemiao 
<[email protected]>
AuthorDate: Wed Dec 13 23:36:25 2023 +0800

    Featrue add insertRecords and insertTablets to the rest v2 service for data 
type verification (#11708)
    
    * Featrue add insertRecords and insertTablets to the rest v2 service for 
data type verification
    
    * Featrue add insertRecords and insertTablets to the rest v2 service for 
data type verification
    
    ---------
    
    Co-authored-by: luke.miao <[email protected]>
---
 .../rest/v2/handler/RequestValidationHandler.java  | 43 ++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/RequestValidationHandler.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/RequestValidationHandler.java
index b7f71f7be6d..5c7fe6724a5 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/RequestValidationHandler.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/v2/handler/RequestValidationHandler.java
@@ -21,9 +21,12 @@ import 
org.apache.iotdb.db.protocol.rest.v2.model.ExpressionRequest;
 import org.apache.iotdb.db.protocol.rest.v2.model.InsertRecordsRequest;
 import org.apache.iotdb.db.protocol.rest.v2.model.InsertTabletRequest;
 import org.apache.iotdb.db.protocol.rest.v2.model.SQL;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
 
 import org.apache.commons.lang3.Validate;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Objects;
 
 public class RequestValidationHandler {
@@ -42,7 +45,22 @@ public class RequestValidationHandler {
     Objects.requireNonNull(insertTabletRequest.getIsAligned(), "is_aligned 
should not be null");
     Objects.requireNonNull(insertTabletRequest.getDevice(), "device should not 
be null");
     Objects.requireNonNull(insertTabletRequest.getDataTypes(), "data_types 
should not be null");
+    Objects.requireNonNull(
+        insertTabletRequest.getMeasurements(), "measurements should not be 
null");
     Objects.requireNonNull(insertTabletRequest.getValues(), "values should not 
be null");
+    List<String> errorMessages = new ArrayList<>();
+    String device = insertTabletRequest.getDevice();
+    for (int i = 0; i < insertTabletRequest.getMeasurements().size(); i++) {
+      String dataType = insertTabletRequest.getDataTypes().get(i);
+      String measurement = insertTabletRequest.getMeasurements().get(i);
+      if (isDataType(dataType)) {
+        errorMessages.add(
+            "The " + dataType + " data type of " + device + "." + measurement 
+ " is illegal");
+      }
+    }
+    if (!errorMessages.isEmpty()) {
+      throw new RuntimeException(String.join(",", errorMessages));
+    }
   }
 
   public static void validateInsertRecordsRequest(InsertRecordsRequest 
insertRecordsRequest) {
@@ -54,6 +72,31 @@ public class RequestValidationHandler {
     Objects.requireNonNull(insertRecordsRequest.getValuesList(), "values_list 
should not be null");
     Objects.requireNonNull(
         insertRecordsRequest.getMeasurementsList(), "measurements_list should 
not be null");
+    List<String> errorMessages = new ArrayList<>();
+    for (int i = 0; i < insertRecordsRequest.getDataTypesList().size(); i++) {
+      String device = insertRecordsRequest.getDevices().get(i);
+      List<String> measurements = 
insertRecordsRequest.getMeasurementsList().get(i);
+      for (int c = 0; c < 
insertRecordsRequest.getDataTypesList().get(i).size(); c++) {
+        String dataType = 
insertRecordsRequest.getDataTypesList().get(i).get(c);
+        String measurement = measurements.get(c);
+        if (isDataType(dataType)) {
+          errorMessages.add(
+              "The " + dataType + " data type of " + device + "." + 
measurement + " is illegal");
+        }
+      }
+    }
+    if (!errorMessages.isEmpty()) {
+      throw new RuntimeException(String.join(",", errorMessages));
+    }
+  }
+
+  private static boolean isDataType(String dataType) {
+    try {
+      TSDataType.valueOf(dataType.toUpperCase());
+    } catch (IllegalArgumentException e) {
+      return true;
+    }
+    return false;
   }
 
   public static void validateExpressionRequest(ExpressionRequest 
expressionRequest) {

Reply via email to