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

haonan pushed a commit to branch iotdb-4542
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 0b18e99e634425e9730ac1d10ec8c69a13d0f592
Author: HTHou <[email protected]>
AuthorDate: Tue Sep 27 19:45:15 2022 +0800

    [IOTDB-4542] Optimize data type mismatch error message
---
 .../iotdb/db/conf/rest/IoTDBRestServiceConfig.java |  2 +-
 .../iotdb/db/mpp/plan/analyze/SchemaValidator.java |  8 ++++++--
 .../plan/node/write/InsertMultiTabletsNode.java    |  8 +++-----
 .../plan/planner/plan/node/write/InsertNode.java   | 16 ++++++++++++----
 .../planner/plan/node/write/InsertRowNode.java     | 22 +++++++++++++---------
 .../planner/plan/node/write/InsertRowsNode.java    | 10 +++++-----
 .../plan/node/write/InsertRowsOfOneDeviceNode.java | 10 +++++-----
 .../planner/plan/node/write/InsertTabletNode.java  | 13 ++++++++++---
 8 files changed, 55 insertions(+), 34 deletions(-)

diff --git 
a/server/src/main/java/org/apache/iotdb/db/conf/rest/IoTDBRestServiceConfig.java
 
b/server/src/main/java/org/apache/iotdb/db/conf/rest/IoTDBRestServiceConfig.java
index ebe3a49a12..162fc47eb7 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/conf/rest/IoTDBRestServiceConfig.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/conf/rest/IoTDBRestServiceConfig.java
@@ -21,7 +21,7 @@ package org.apache.iotdb.db.conf.rest;
 public class IoTDBRestServiceConfig {
   static final String CONFIG_NAME = "iotdb-rest.properties";
   /** if the enableRestService is true, we will start REST Service */
-  private boolean enableRestService = false;
+  private boolean enableRestService = true;
 
   /** set the REST Service port. */
   private int restServicePort = 18080;
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/SchemaValidator.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/SchemaValidator.java
index f40e82abb4..bceb07d210 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/SchemaValidator.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/analyze/SchemaValidator.java
@@ -19,8 +19,10 @@
 
 package org.apache.iotdb.db.mpp.plan.analyze;
 
+import org.apache.iotdb.commons.exception.MetadataException;
 import org.apache.iotdb.commons.path.PartialPath;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.exception.query.QueryProcessException;
 import org.apache.iotdb.db.exception.sql.SemanticException;
 import org.apache.iotdb.db.mpp.common.schematree.ISchemaTree;
 import org.apache.iotdb.db.mpp.plan.planner.plan.node.write.BatchInsertNode;
@@ -58,8 +60,10 @@ public class SchemaValidator {
               insertNode.isAligned());
     }
 
-    if (!insertNode.validateAndSetSchema(schemaTree)) {
-      throw new SemanticException("Data type mismatch");
+    try {
+      insertNode.validateAndSetSchema(schemaTree);
+    } catch (QueryProcessException | MetadataException e) {
+      throw new SemanticException(e.getMessage());
     }
 
     return schemaTree;
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertMultiTabletsNode.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertMultiTabletsNode.java
index a48f366a7f..be8e90b914 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertMultiTabletsNode.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertMultiTabletsNode.java
@@ -20,6 +20,7 @@ package org.apache.iotdb.db.mpp.plan.planner.plan.node.write;
 
 import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
 import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.exception.MetadataException;
 import org.apache.iotdb.commons.path.PartialPath;
 import org.apache.iotdb.commons.utils.StatusUtils;
 import org.apache.iotdb.db.mpp.common.schematree.ISchemaTree;
@@ -136,16 +137,13 @@ public class InsertMultiTabletsNode extends InsertNode 
implements BatchInsertNod
   }
 
   @Override
-  public boolean validateAndSetSchema(ISchemaTree schemaTree) {
+  public void validateAndSetSchema(ISchemaTree schemaTree) throws 
MetadataException {
     for (InsertTabletNode insertTabletNode : insertTabletNodeList) {
-      if (!insertTabletNode.validateAndSetSchema(schemaTree)) {
-        return false;
-      }
+      insertTabletNode.validateAndSetSchema(schemaTree);
       if (!this.hasFailedMeasurements() && 
insertTabletNode.hasFailedMeasurements()) {
         this.failedMeasurementIndex2Info = 
insertTabletNode.failedMeasurementIndex2Info;
       }
     }
-    return true;
   }
 
   @Override
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertNode.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertNode.java
index 5a2c11c890..5e41f00adb 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertNode.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertNode.java
@@ -19,10 +19,12 @@
 package org.apache.iotdb.db.mpp.plan.planner.plan.node.write;
 
 import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
+import org.apache.iotdb.commons.exception.MetadataException;
 import org.apache.iotdb.commons.path.PartialPath;
 import org.apache.iotdb.consensus.multileader.wal.ConsensusReqReader;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.exception.metadata.DataTypeMismatchException;
+import org.apache.iotdb.db.exception.query.QueryProcessException;
 import org.apache.iotdb.db.metadata.idtable.entry.IDeviceID;
 import org.apache.iotdb.db.mpp.common.schematree.ISchemaTree;
 import org.apache.iotdb.db.mpp.plan.planner.plan.node.PlanNodeId;
@@ -240,17 +242,24 @@ public abstract class InsertNode extends WritePlanNode {
     return dataRegionReplicaSet;
   }
 
-  public abstract boolean validateAndSetSchema(ISchemaTree schemaTree);
+  public abstract void validateAndSetSchema(ISchemaTree schemaTree)
+      throws QueryProcessException, MetadataException;
 
   /** Check whether data types are matched with measurement schemas */
-  protected boolean selfCheckDataTypes() {
+  protected void selfCheckDataTypes() throws DataTypeMismatchException {
     for (int i = 0; i < measurementSchemas.length; i++) {
       if (dataTypes[i] != measurementSchemas[i].getType()) {
         if (checkAndCastDataType(i, measurementSchemas[i].getType())) {
           continue;
         }
         if 
(!IoTDBDescriptor.getInstance().getConfig().isEnablePartialInsert()) {
-          return false;
+          throw new DataTypeMismatchException(
+              devicePath.getFullPath(),
+              measurements[i],
+              dataTypes[i],
+              measurementSchemas[i].getType(),
+              getMinTime(),
+              getFirstValueOfIndex(i));
         } else {
           markFailedMeasurement(
               i,
@@ -264,7 +273,6 @@ public abstract class InsertNode extends WritePlanNode {
         }
       }
     }
-    return true;
   }
 
   protected abstract boolean checkAndCastDataType(int columnIndex, TSDataType 
dataType);
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertRowNode.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertRowNode.java
index d8e8c1030e..8b4cc6fa36 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertRowNode.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertRowNode.java
@@ -21,9 +21,11 @@ package org.apache.iotdb.db.mpp.plan.planner.plan.node.write;
 import org.apache.iotdb.common.rpc.thrift.TTimePartitionSlot;
 import org.apache.iotdb.commons.conf.IoTDBConstant;
 import org.apache.iotdb.commons.exception.IllegalPathException;
+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.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.exception.metadata.AlignedTimeseriesException;
 import org.apache.iotdb.db.exception.metadata.PathNotExistException;
 import org.apache.iotdb.db.exception.query.QueryProcessException;
 import org.apache.iotdb.db.mpp.common.schematree.DeviceSchemaInfo;
@@ -178,27 +180,29 @@ public class InsertRowNode extends InsertNode implements 
WALEntryValue {
   }
 
   @Override
-  public boolean validateAndSetSchema(ISchemaTree schemaTree) {
+  public void validateAndSetSchema(ISchemaTree schemaTree)
+      throws QueryProcessException, MetadataException {
     DeviceSchemaInfo deviceSchemaInfo =
         schemaTree.searchDeviceSchemaInfo(devicePath, 
Arrays.asList(measurements));
     if (deviceSchemaInfo.isAligned() != isAligned) {
-      return false;
+      throw new AlignedTimeseriesException(
+          String.format(
+              "timeseries under this device are%s aligned, " + "please use %s 
interface",
+              deviceSchemaInfo.isAligned() ? "" : " not",
+              deviceSchemaInfo.isAligned() ? "aligned" : "non-aligned"),
+          devicePath.getFullPath());
     }
     this.measurementSchemas =
         deviceSchemaInfo.getMeasurementSchemaList().toArray(new 
MeasurementSchema[0]);
 
     // transfer data types from string values when necessary
     if (isNeedInferType) {
-      try {
-        transferType();
-        return true;
-      } catch (QueryProcessException e) {
-        return false;
-      }
+      transferType();
+      return;
     }
 
     // validate whether data types are matched
-    return selfCheckDataTypes();
+    selfCheckDataTypes();
   }
 
   @Override
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertRowsNode.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertRowsNode.java
index 0ca29b9c75..1fe827eccc 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertRowsNode.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertRowsNode.java
@@ -20,8 +20,10 @@ package org.apache.iotdb.db.mpp.plan.planner.plan.node.write;
 
 import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
 import org.apache.iotdb.common.rpc.thrift.TSStatus;
+import org.apache.iotdb.commons.exception.MetadataException;
 import org.apache.iotdb.commons.path.PartialPath;
 import org.apache.iotdb.commons.utils.StatusUtils;
+import org.apache.iotdb.db.exception.query.QueryProcessException;
 import org.apache.iotdb.db.mpp.common.schematree.ISchemaTree;
 import org.apache.iotdb.db.mpp.plan.analyze.Analysis;
 import org.apache.iotdb.db.mpp.plan.planner.plan.node.PlanNode;
@@ -120,16 +122,14 @@ public class InsertRowsNode extends InsertNode implements 
BatchInsertNode {
   public void addChild(PlanNode child) {}
 
   @Override
-  public boolean validateAndSetSchema(ISchemaTree schemaTree) {
+  public void validateAndSetSchema(ISchemaTree schemaTree)
+      throws QueryProcessException, MetadataException {
     for (InsertRowNode insertRowNode : insertRowNodeList) {
-      if (!insertRowNode.validateAndSetSchema(schemaTree)) {
-        return false;
-      }
+      insertRowNode.validateAndSetSchema(schemaTree);
       if (!this.hasFailedMeasurements() && 
insertRowNode.hasFailedMeasurements()) {
         this.failedMeasurementIndex2Info = 
insertRowNode.failedMeasurementIndex2Info;
       }
     }
-    return true;
   }
 
   @Override
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertRowsOfOneDeviceNode.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertRowsOfOneDeviceNode.java
index bb1f69d25c..52d11d444e 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertRowsOfOneDeviceNode.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertRowsOfOneDeviceNode.java
@@ -21,8 +21,10 @@ package org.apache.iotdb.db.mpp.plan.planner.plan.node.write;
 import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
 import org.apache.iotdb.common.rpc.thrift.TSStatus;
 import org.apache.iotdb.commons.exception.IllegalPathException;
+import org.apache.iotdb.commons.exception.MetadataException;
 import org.apache.iotdb.commons.path.PartialPath;
 import org.apache.iotdb.commons.utils.StatusUtils;
+import org.apache.iotdb.db.exception.query.QueryProcessException;
 import org.apache.iotdb.db.mpp.common.schematree.ISchemaTree;
 import org.apache.iotdb.db.mpp.plan.analyze.Analysis;
 import org.apache.iotdb.db.mpp.plan.planner.plan.node.PlanNode;
@@ -143,17 +145,15 @@ public class InsertRowsOfOneDeviceNode extends InsertNode 
implements BatchInsert
   }
 
   @Override
-  public boolean validateAndSetSchema(ISchemaTree schemaTree) {
+  public void validateAndSetSchema(ISchemaTree schemaTree)
+      throws QueryProcessException, MetadataException {
     for (InsertRowNode insertRowNode : insertRowNodeList) {
-      if (!insertRowNode.validateAndSetSchema(schemaTree)) {
-        return false;
-      }
+      insertRowNode.validateAndSetSchema(schemaTree);
       if (!this.hasFailedMeasurements() && 
insertRowNode.hasFailedMeasurements()) {
         this.failedMeasurementIndex2Info = 
insertRowNode.failedMeasurementIndex2Info;
       }
     }
     storeMeasurementsAndDataType();
-    return true;
   }
 
   @Override
diff --git 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertTabletNode.java
 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertTabletNode.java
index 0b5742e7a2..ac84f71e0d 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertTabletNode.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/mpp/plan/planner/plan/node/write/InsertTabletNode.java
@@ -21,10 +21,12 @@ package 
org.apache.iotdb.db.mpp.plan.planner.plan.node.write;
 import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
 import org.apache.iotdb.common.rpc.thrift.TTimePartitionSlot;
 import org.apache.iotdb.commons.exception.IllegalPathException;
+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.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.conf.ServerConfigConsistent;
+import org.apache.iotdb.db.exception.metadata.AlignedTimeseriesException;
 import org.apache.iotdb.db.mpp.common.schematree.DeviceSchemaInfo;
 import org.apache.iotdb.db.mpp.common.schematree.ISchemaTree;
 import org.apache.iotdb.db.mpp.plan.analyze.Analysis;
@@ -178,17 +180,22 @@ public class InsertTabletNode extends InsertNode 
implements WALEntryValue {
   }
 
   @Override
-  public boolean validateAndSetSchema(ISchemaTree schemaTree) {
+  public void validateAndSetSchema(ISchemaTree schemaTree) throws 
MetadataException {
     DeviceSchemaInfo deviceSchemaInfo =
         schemaTree.searchDeviceSchemaInfo(devicePath, 
Arrays.asList(measurements));
     if (deviceSchemaInfo.isAligned() != isAligned) {
-      return false;
+      throw new AlignedTimeseriesException(
+          String.format(
+              "timeseries under this device are%s aligned, " + "please use %s 
interface",
+              deviceSchemaInfo.isAligned() ? "" : " not",
+              deviceSchemaInfo.isAligned() ? "aligned" : "non-aligned"),
+          devicePath.getFullPath());
     }
     measurementSchemas =
         deviceSchemaInfo.getMeasurementSchemaList().toArray(new 
MeasurementSchema[0]);
 
     // validate whether data types are matched
-    return selfCheckDataTypes();
+    selfCheckDataTypes();
   }
 
   @Override

Reply via email to