You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2023/07/06 11:10:16 UTC
[iotdb] branch rel/1.2 updated: [To rel/1.2] Make error message more accurate when failed to inserting alias timeseries
This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch rel/1.2
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/1.2 by this push:
new 3b53ab0cf12 [To rel/1.2] Make error message more accurate when failed to inserting alias timeseries
3b53ab0cf12 is described below
commit 3b53ab0cf1241759ee2e5aba3d885ad950eaa684
Author: Chen YZ <43...@users.noreply.github.com>
AuthorDate: Thu Jul 6 19:10:09 2023 +0800
[To rel/1.2] Make error message more accurate when failed to inserting alias timeseries
---
.../db/it/schema/view/IoTDBAliasSeriesIT.java | 29 ++++++++++++++++++++++
.../exception/metadata/PathNotExistException.java | 8 ++++++
.../mpp/common/schematree/ClusterSchemaTree.java | 24 +++++++++++-------
3 files changed, 52 insertions(+), 9 deletions(-)
diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/view/IoTDBAliasSeriesIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/view/IoTDBAliasSeriesIT.java
index 2045f23b59e..266c63a1c57 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/view/IoTDBAliasSeriesIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/view/IoTDBAliasSeriesIT.java
@@ -99,4 +99,33 @@ public class IoTDBAliasSeriesIT {
}
}
}
+
+ @Test
+ public void testInsertIntoViewSourceNotExist() throws Exception {
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.execute("CREATE DATABASE root.db");
+ statement.execute("CREATE TIMESERIES root.db.device.s01 with datatype=BOOLEAN");
+ statement.execute("CREATE VIEW root.db.device.v_s01 AS root.db.device.s01");
+ statement.execute("DELETE timeseries root.db.device.s01;");
+ try {
+ statement.execute("insert into root.db.device(time,s01,v_s01) values(1,true,true)");
+ Assert.fail("expect exception");
+ } catch (Exception e) {
+ Assert.assertTrue(
+ e.getMessage()
+ .contains(
+ "Insertion is illegal because measurement [s01] under device [root.db.device] is duplicate"));
+ }
+ try {
+ statement.execute("insert into root.db.device(time,v_s01) values(1,true)");
+ Assert.fail("expect exception");
+ } catch (Exception e) {
+ Assert.assertTrue(
+ e.getMessage()
+ .contains(
+ "The source path [root.db.device.s01] of view [root.db.device.v_s01] does not exist"));
+ }
+ }
+ }
}
diff --git a/server/src/main/java/org/apache/iotdb/db/exception/metadata/PathNotExistException.java b/server/src/main/java/org/apache/iotdb/db/exception/metadata/PathNotExistException.java
index f608eac02a4..056157763fc 100644
--- a/server/src/main/java/org/apache/iotdb/db/exception/metadata/PathNotExistException.java
+++ b/server/src/main/java/org/apache/iotdb/db/exception/metadata/PathNotExistException.java
@@ -27,6 +27,8 @@ import java.util.List;
public class PathNotExistException extends MetadataException {
private static final String PATH_NOT_EXIST_WRONG_MESSAGE = "Path [%s] does not exist";
+ private static final String SOURCE_PATH_NOT_EXIST_WRONG_MESSAGE =
+ "The source path [%s] of view [%s] does not exist.";
private static final String NORMAL_TIMESERIES_NOT_EXIST_WRONG_MESSAGE =
"Timeseries [%s] does not exist or is represented by schema template";
@@ -34,6 +36,12 @@ public class PathNotExistException extends MetadataException {
private static final String TEMPLATE_TIMESERIES_NOT_EXIST_WRONG_MESSAGE =
"Timeseries [%s] does not exist or is not represented by schema template";
+ public PathNotExistException(String sourcePath, String viewPath) {
+ super(
+ String.format(SOURCE_PATH_NOT_EXIST_WRONG_MESSAGE, sourcePath, viewPath),
+ TSStatusCode.PATH_NOT_EXIST.getStatusCode());
+ }
+
public PathNotExistException(String path) {
super(
String.format(PATH_NOT_EXIST_WRONG_MESSAGE, path),
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/ClusterSchemaTree.java b/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/ClusterSchemaTree.java
index 94eb822ba5e..083c57209c3 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/ClusterSchemaTree.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/ClusterSchemaTree.java
@@ -25,6 +25,7 @@ import org.apache.iotdb.commons.schema.view.LogicalViewSchema;
import org.apache.iotdb.commons.utils.PathUtils;
import org.apache.iotdb.commons.utils.TestOnly;
import org.apache.iotdb.db.exception.metadata.PathNotExistException;
+import org.apache.iotdb.db.exception.sql.SemanticException;
import org.apache.iotdb.db.mpp.common.schematree.node.SchemaEntityNode;
import org.apache.iotdb.db.mpp.common.schematree.node.SchemaInternalNode;
import org.apache.iotdb.db.mpp.common.schematree.node.SchemaMeasurementNode;
@@ -40,7 +41,6 @@ import org.apache.iotdb.tsfile.write.schema.IMeasurementSchema;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.rmi.UnexpectedException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
@@ -214,16 +214,22 @@ public class ClusterSchemaTree implements ISchemaTree {
PartialPath fullPath = logicalViewSchema.getSourcePathIfWritable();
Pair<List<MeasurementPath>, Integer> searchResult = this.searchMeasurementPaths(fullPath);
List<MeasurementPath> measurementPathList = searchResult.left;
- if (measurementPathList.size() <= 0) {
- throw new RuntimeException(
+ if (measurementPathList.isEmpty()) {
+ throw new SemanticException(
new PathNotExistException(
- String.format(
- "The source path of view [%s] does not exist.", fullPath.getFullPath())));
+ fullPath.getFullPath(),
+ schemaComputation
+ .getDevicePath()
+ .concatNode(logicalViewSchema.getMeasurementId())
+ .getFullPath()));
} else if (measurementPathList.size() > 1) {
- throw new RuntimeException(
- new UnexpectedException(
- String.format(
- "The source paths of view [%s] are multiple.", fullPath.getFullPath())));
+ throw new SemanticException(
+ String.format(
+ "The source paths [%s] of view [%s] are multiple.",
+ fullPath.getFullPath(),
+ schemaComputation
+ .getDevicePath()
+ .concatNode(logicalViewSchema.getMeasurementId())));
} else {
Integer realIndex = schemaComputation.getIndexListOfLogicalViewPaths().get(index);
MeasurementPath measurementPath = measurementPathList.get(0);