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 d26acabc0a [IOTDB-4542] Optimize schema validate error message (#7456)
d26acabc0a is described below

commit d26acabc0aaeadcfc1140d9822b94425baf3c078
Author: Haonan <[email protected]>
AuthorDate: Wed Sep 28 15:00:16 2022 +0800

    [IOTDB-4542] Optimize schema validate error message (#7456)
---
 .../db/it/aligned/IoTDBInsertAlignedValuesIT.java  | 34 ++++++++++++++++++++++
 .../apache/iotdb/session/IoTDBSessionSimpleIT.java |  2 +-
 .../schemaregion/rocksdb/RSchemaRegion.java        | 16 ++++------
 .../schemaregion/SchemaRegionMemoryImpl.java       | 15 +++++-----
 .../schemaregion/SchemaRegionSchemaFileImpl.java   | 16 +++++-----
 .../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 +++++++--
 .../apache/iotdb/db/metadata/SchemaBasicTest.java  |  4 +--
 13 files changed, 112 insertions(+), 62 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBInsertAlignedValuesIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBInsertAlignedValuesIT.java
index 475f5ae274..a2f0c93d24 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBInsertAlignedValuesIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/aligned/IoTDBInsertAlignedValuesIT.java
@@ -265,6 +265,40 @@ public class IoTDBInsertAlignedValuesIT {
     }
   }
 
+  @Test
+  public void testInsertAlignedTimeseriesWithoutAligned() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute(
+          "CREATE ALIGNED TIMESERIES root.lz.dev.GPS2(latitude INT32 
encoding=PLAIN compressor=SNAPPY, longitude INT32 encoding=PLAIN 
compressor=SNAPPY) ");
+      statement.execute("insert into root.lz.dev.GPS2(time,latitude,longitude) 
values(1,1.3,6.7)");
+      fail();
+    } catch (SQLException e) {
+      assertTrue(
+          e.getMessage(),
+          e.getMessage()
+              .contains("timeseries under this device are aligned, please use 
aligned interface"));
+    }
+  }
+
+  @Test
+  public void testInsertNonAlignedTimeseriesWithAligned() {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      statement.execute("CREATE TIMESERIES root.lz.dev.GPS3.latitude with 
datatype=INT32");
+      statement.execute("CREATE TIMESERIES root.lz.dev.GPS3.longitude with 
datatype=INT32");
+      statement.execute(
+          "insert into root.lz.dev.GPS3(time,latitude,longitude) aligned 
values(1,1.3,6.7)");
+      fail();
+    } catch (SQLException e) {
+      assertTrue(
+          e.getMessage(),
+          e.getMessage()
+              .contains(
+                  "timeseries under this device are not aligned, please use 
non-aligned interface"));
+    }
+  }
+
   @Test
   public void testInsertAlignedValuesWithThreeLevelPath() throws SQLException {
     try (Connection connection = EnvFactory.getEnv().getConnection();
diff --git 
a/integration/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java 
b/integration/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java
index 7e135e56ae..0e7c445b61 100644
--- 
a/integration/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java
+++ 
b/integration/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java
@@ -1282,7 +1282,7 @@ public class IoTDBSessionSimpleIT {
       session.insertAlignedRecord("root.sg.loc1.sector.GPS", 3L, measurements, 
values);
     } catch (StatementExecutionException e) {
       assertEquals(
-          "303: Timeseries under path [root.sg.loc1.sector.GPS] is not aligned 
, please set InsertPlan.isAligned() = false",
+          "319: timeseries under this device are not aligned, please use 
non-aligned interface (Path: root.sg.loc1.sector.GPS)",
           e.getMessage());
     }
 
diff --git 
a/schema-engine-rocksdb/src/main/java/org/apache/iotdb/db/metadata/schemaregion/rocksdb/RSchemaRegion.java
 
b/schema-engine-rocksdb/src/main/java/org/apache/iotdb/db/metadata/schemaregion/rocksdb/RSchemaRegion.java
index 7bfd9c4b8b..3575e027c9 100644
--- 
a/schema-engine-rocksdb/src/main/java/org/apache/iotdb/db/metadata/schemaregion/rocksdb/RSchemaRegion.java
+++ 
b/schema-engine-rocksdb/src/main/java/org/apache/iotdb/db/metadata/schemaregion/rocksdb/RSchemaRegion.java
@@ -1838,19 +1838,15 @@ public class RSchemaRegion implements ISchemaRegion {
     // check insert non-aligned InsertPlan for aligned timeseries
     if (deviceMNode.isEntity()) {
       if (plan.isAligned() && !deviceMNode.getAsEntityMNode().isAligned()) {
-        throw new MetadataException(
-            String.format(
-                "Timeseries under path [%s] is not aligned , please set"
-                    + " InsertPlan.isAligned() = false",
-                plan.getDevicePath()));
+        throw new AlignedTimeseriesException(
+            "timeseries under this device are not aligned, " + "please use 
non-aligned interface",
+            devicePath.getFullPath());
       }
 
       if (!plan.isAligned() && deviceMNode.getAsEntityMNode().isAligned()) {
-        throw new MetadataException(
-            String.format(
-                "Timeseries under path [%s] is aligned , please set"
-                    + " InsertPlan.isAligned() = true",
-                plan.getDevicePath()));
+        throw new AlignedTimeseriesException(
+            "timeseries under this device are aligned, " + "please use aligned 
interface",
+            devicePath.getFullPath());
       }
     }
 
diff --git 
a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionMemoryImpl.java
 
b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionMemoryImpl.java
index f56c2cfda3..d0a26368e8 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionMemoryImpl.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionMemoryImpl.java
@@ -32,6 +32,7 @@ import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.engine.StorageEngine;
 import org.apache.iotdb.db.engine.trigger.executor.TriggerEngine;
 import org.apache.iotdb.db.exception.metadata.AliasAlreadyExistException;
+import org.apache.iotdb.db.exception.metadata.AlignedTimeseriesException;
 import org.apache.iotdb.db.exception.metadata.DataTypeMismatchException;
 import org.apache.iotdb.db.exception.metadata.DeleteFailedException;
 import org.apache.iotdb.db.exception.metadata.PathAlreadyExistException;
@@ -1691,17 +1692,15 @@ public class SchemaRegionMemoryImpl implements 
ISchemaRegion {
     if (deviceMNode.isEntity()) {
       if (plan.isAligned()) {
         if (!deviceMNode.getAsEntityMNode().isAligned()) {
-          throw new MetadataException(
-              String.format(
-                  "Timeseries under path [%s] is not aligned , please set 
InsertPlan.isAligned() = false",
-                  plan.getDevicePath()));
+          throw new AlignedTimeseriesException(
+              "timeseries under this device are not aligned, " + "please use 
non-aligned interface",
+              devicePath.getFullPath());
         }
       } else {
         if (deviceMNode.getAsEntityMNode().isAligned()) {
-          throw new MetadataException(
-              String.format(
-                  "Timeseries under path [%s] is aligned , please set 
InsertPlan.isAligned() = true",
-                  plan.getDevicePath()));
+          throw new AlignedTimeseriesException(
+              "timeseries under this device are aligned, " + "please use 
aligned interface",
+              devicePath.getFullPath());
         }
       }
     }
diff --git 
a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionSchemaFileImpl.java
 
b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionSchemaFileImpl.java
index 0c3f8038bf..e54f91fc33 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionSchemaFileImpl.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionSchemaFileImpl.java
@@ -30,6 +30,7 @@ import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.engine.StorageEngine;
 import org.apache.iotdb.db.engine.trigger.executor.TriggerEngine;
 import org.apache.iotdb.db.exception.metadata.AliasAlreadyExistException;
+import org.apache.iotdb.db.exception.metadata.AlignedTimeseriesException;
 import org.apache.iotdb.db.exception.metadata.DataTypeMismatchException;
 import org.apache.iotdb.db.exception.metadata.DeleteFailedException;
 import org.apache.iotdb.db.exception.metadata.PathAlreadyExistException;
@@ -1584,17 +1585,16 @@ public class SchemaRegionSchemaFileImpl implements 
ISchemaRegion {
       if (deviceMNode.isEntity()) {
         if (plan.isAligned()) {
           if (!deviceMNode.getAsEntityMNode().isAligned()) {
-            throw new MetadataException(
-                String.format(
-                    "Timeseries under path [%s] is not aligned , please set 
InsertPlan.isAligned() = false",
-                    plan.getDevicePath()));
+            throw new AlignedTimeseriesException(
+                "timeseries under this device are not aligned, "
+                    + "please use non-aligned interface",
+                devicePath.getFullPath());
           }
         } else {
           if (deviceMNode.getAsEntityMNode().isAligned()) {
-            throw new MetadataException(
-                String.format(
-                    "Timeseries under path [%s] is aligned , please set 
InsertPlan.isAligned() = true",
-                    plan.getDevicePath()));
+            throw new AlignedTimeseriesException(
+                "timeseries under this device are aligned, " + "please use 
aligned interface",
+                devicePath.getFullPath());
           }
         }
       }
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 76d0cc7458..78dc4ed767 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,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.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.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;
@@ -172,17 +174,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
diff --git 
a/server/src/test/java/org/apache/iotdb/db/metadata/SchemaBasicTest.java 
b/server/src/test/java/org/apache/iotdb/db/metadata/SchemaBasicTest.java
index a6a383d9fa..c836b55ec2 100644
--- a/server/src/test/java/org/apache/iotdb/db/metadata/SchemaBasicTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/metadata/SchemaBasicTest.java
@@ -2060,7 +2060,7 @@ public abstract class SchemaBasicTest {
       fail();
     } catch (Exception e) {
       Assert.assertEquals(
-          "Timeseries under path [root.laptop.d1.aligned_device] is aligned , 
please set InsertPlan.isAligned() = true",
+          "timeseries under this device are aligned, please use aligned 
interface (Path: root.laptop.d1.aligned_device)",
           e.getMessage());
     }
   }
@@ -2167,7 +2167,7 @@ public abstract class SchemaBasicTest {
       fail();
     } catch (Exception e) {
       Assert.assertEquals(
-          "Timeseries under path [root.laptop.d1.aligned_device] is not 
aligned , please set InsertPlan.isAligned() = false",
+          "timeseries under this device are not aligned, please use 
non-aligned interface (Path: root.laptop.d1.aligned_device)",
           e.getMessage());
     }
   }

Reply via email to