You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2021/01/26 03:12:51 UTC

[iotdb] branch node_matcher created (now c0dcc8c)

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

haonan pushed a change to branch node_matcher
in repository https://gitbox.apache.org/repos/asf/iotdb.git.


      at c0dcc8c  add some tests

This branch includes the following new commits:

     new 32e384a  add create timeseries path checker
     new c0dcc8c  add some tests

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[iotdb] 01/02: add create timeseries path checker

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 32e384ae679e828ce85ef4139fe9633ed9378bbe
Author: HTHou <hh...@outlook.com>
AuthorDate: Tue Jan 26 10:30:18 2021 +0800

    add create timeseries path checker
---
 server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java |  2 ++
 server/src/main/java/org/apache/iotdb/db/metadata/MTree.java   |  9 +++++++++
 .../java/org/apache/iotdb/db/qp/executor/PlanExecutor.java     | 10 ++++++++--
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
index 8ed06b0..eb61cb3 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
@@ -63,6 +63,8 @@ public class IoTDBConfig {
 
   public static final Pattern STORAGE_GROUP_PATTERN = Pattern.compile(STORAGE_GROUP_MATCHER);
 
+  public static final Pattern NODE_PATTERN = Pattern.compile(NODE_MATCHER);
+  
   /**
    * Port which the metrics service listens to.
    */
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
index c204459..7f81c3f 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
@@ -196,6 +196,7 @@ public class MTree implements Serializable {
     if (nodeNames.length <= 2 || !nodeNames[0].equals(root.getName())) {
       throw new IllegalPathException(path.getFullPath());
     }
+    checkTimeseries(path.getFullPath());
     MNode cur = root;
     boolean hasSetStorageGroup = false;
     // e.g, path = root.sg.d1.s1,  create internal nodes and set cur to d1 node
@@ -237,6 +238,14 @@ public class MTree implements Serializable {
     }
   }
 
+  private void checkTimeseries(String timeseries) throws IllegalPathException {
+    if (!IoTDBConfig.NODE_PATTERN.matcher(timeseries).matches()) {
+      throw new IllegalPathException(String
+          .format("The timeseries name contains unsupported character. %s",
+              timeseries));
+    }
+  }
+
   /**
    * Add an interval path to MTree. This is only used for automatically creating schema
    *
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
index ff1ced1..deebba1 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/executor/PlanExecutor.java
@@ -1027,7 +1027,8 @@ public class PlanExecutor implements IPlanExecutor {
       throw new PathNotExistException(failedPaths);
     } else {
       throw new StorageEngineException(
-          INSERT_MEASUREMENTS_FAILED_MESSAGE + plan.getFailedMeasurements());
+          INSERT_MEASUREMENTS_FAILED_MESSAGE + plan.getFailedMeasurements() 
+          + (!exceptions.isEmpty() ? (" caused by " + exceptions.get(0).getMessage()) : "" ));
     }
   }
 
@@ -1046,6 +1047,9 @@ public class PlanExecutor implements IPlanExecutor {
 
       List<String> notExistedPaths = null;
       List<String> failedMeasurements = null;
+
+      // If there are some exceptions, we assume they caused by the same reason.
+      Exception exception = null;
       for (InsertRowPlan plan : insertRowsOfOneDevicePlan.getRowPlans()) {
         if (plan.getFailedMeasurements() != null) {
           if (notExistedPaths == null) {
@@ -1057,6 +1061,7 @@ public class PlanExecutor implements IPlanExecutor {
           List<Exception> exceptions = plan.getFailedExceptions();
           boolean isPathNotExistException = true;
           for (Exception e : exceptions) {
+            exception = e;
             Throwable curException = e;
             while (curException.getCause() != null) {
               curException = curException.getCause();
@@ -1077,7 +1082,8 @@ public class PlanExecutor implements IPlanExecutor {
         throw new PathNotExistException(notExistedPaths);
       } else if (notExistedPaths != null && !failedMeasurements.isEmpty()) {
         throw new StorageEngineException(
-            "failed to insert points " + failedMeasurements);
+            "failed to insert points " + failedMeasurements
+            + (exception != null ? (" caused by " + exception.getMessage()) : "" ));
       }
 
     } catch (StorageEngineException | MetadataException e) {


[iotdb] 02/02: add some tests

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit c0dcc8cad869f642d24c3e47418af3308068b485
Author: HTHou <hh...@outlook.com>
AuthorDate: Tue Jan 26 11:12:10 2021 +0800

    add some tests
---
 .../java/org/apache/iotdb/db/conf/IoTDBConfig.java |  1 +
 .../iotdb/db/metadata/MManagerBasicTest.java       | 32 ++++++++++++++++++++++
 .../apache/iotdb/session/IoTDBSessionSimpleIT.java | 31 ++++++++++++++++++++-
 3 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
index eb61cb3..d2d2b60 100644
--- a/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
+++ b/server/src/main/java/org/apache/iotdb/db/conf/IoTDBConfig.java
@@ -58,6 +58,7 @@ public class IoTDBConfig {
   private static final String PARTIAL_NODE_MATCHER = "[" + PATH_SEPARATOR + "]" + ID_MATCHER;
 
   // for path like: root.sg1.d1."1.2.3", root.sg.d1."1.2.3"
+  // TODO: need a correct NODE_MATCHER for checking timeseries format
   private static final String NODE_MATCHER =
       "[" + PATH_SEPARATOR + "]([\"])?" + ID_MATCHER + "(" + PARTIAL_NODE_MATCHER + ")*([\"])?";
 
diff --git a/server/src/test/java/org/apache/iotdb/db/metadata/MManagerBasicTest.java b/server/src/test/java/org/apache/iotdb/db/metadata/MManagerBasicTest.java
index 46ca280..c4c9a05 100644
--- a/server/src/test/java/org/apache/iotdb/db/metadata/MManagerBasicTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/metadata/MManagerBasicTest.java
@@ -365,6 +365,38 @@ public class MManagerBasicTest {
   }
 
   @Test
+  public void testSetStorageGroupWithIllegalName() {
+    MManager manager = IoTDB.metaManager;
+    try {
+      manager.setStorageGroup(new PartialPath("root.laptop\n"));
+      fail();
+    } catch (MetadataException e) {
+    }
+    try {
+      manager.setStorageGroup(new PartialPath("root.laptop\t"));
+      fail();
+    } catch (MetadataException e) {
+    }
+  }
+
+  @Test
+  public void testCreateTimeseriesWithIllegalName() {
+    MManager manager = IoTDB.metaManager;
+    try {
+      manager.createTimeseries(new PartialPath("root.laptop.d1\n.s1"), TSDataType.INT32, TSEncoding.PLAIN,
+          CompressionType.SNAPPY, null);
+      fail();
+    } catch (MetadataException e) {
+    }
+    try {
+      manager.createTimeseries(new PartialPath("root.laptop.d1\t.s1"), TSDataType.INT32, TSEncoding.PLAIN,
+          CompressionType.SNAPPY, null);
+      fail();
+    } catch (MetadataException e) {
+    }
+  }
+
+  @Test
   public void testGetDevicesWithGivenPrefix() {
     MManager manager = IoTDB.metaManager;
 
diff --git a/session/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java b/session/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java
index d0a070d..b9571bc 100644
--- a/session/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java
+++ b/session/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java
@@ -24,7 +24,6 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -212,6 +211,36 @@ public class IoTDBSessionSimpleIT {
   }
 
   @Test
+  public void testInsertIntoIllegalTimeseries()
+      throws IoTDBConnectionException, StatementExecutionException {
+    session = new Session("127.0.0.1", 6667, "root", "root");
+    session.open();
+
+    String deviceId = "root.sg1.d1\n";
+    List<String> measurements = new ArrayList<>();
+    measurements.add("s1");
+    measurements.add("s2");
+    measurements.add("s3");
+    measurements.add("s4");
+
+    List<String> values = new ArrayList<>();
+    values.add("1");
+    values.add("1.2");
+    values.add("true");
+    values.add("dad");
+    try {
+      session.insertRecord(deviceId, 1L, measurements, values);
+    } catch (Exception e) {
+      logger.error("" ,e);
+    }
+    
+    SessionDataSet dataSet = session.executeQueryStatement("show timeseries root");
+    Assert.assertFalse(dataSet.hasNext());
+
+    session.close();
+  }
+
+  @Test
   public void testInsertByObjAndNotInferType()
       throws IoTDBConnectionException, StatementExecutionException {
     session = new Session("127.0.0.1", 6667, "root", "root");