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

hxd 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 2957859  [ISSUE-2573] Create timeseries root.sg.d1\n.s1 should be 
disabled using native session api (#2578)
2957859 is described below

commit 29578599ddd1c315e4a7a234acbabe140fd2e192
Author: Haonan <[email protected]>
AuthorDate: Thu Jan 28 17:05:36 2021 +0800

    [ISSUE-2573] Create timeseries root.sg.d1\n.s1 should be disabled using 
native session api (#2578)
---
 .../java/org/apache/iotdb/db/conf/IoTDBConfig.java |  7 ++-
 .../java/org/apache/iotdb/db/metadata/MTree.java   |  9 ++++
 .../apache/iotdb/db/qp/executor/PlanExecutor.java  | 10 +++-
 .../iotdb/db/integration/IoTDBDeletionIT.java      |  1 -
 .../iotdb/db/metadata/MManagerBasicTest.java       | 53 +++++++++++++++++++++-
 .../apache/iotdb/session/IoTDBSessionSimpleIT.java | 31 ++++++++++++-
 6 files changed, 104 insertions(+), 7 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..988469a 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
@@ -50,7 +50,7 @@ public class IoTDBConfig {
   private static final String DEFAULT_MULTI_DIR_STRATEGY = 
"MaxDiskUsableSpaceFirstStrategy";
 
   // e.g., a31+/$%#&[]{}3e4
-  private static final String ID_MATCHER = 
"([a-zA-Z0-9/@#$%&{}\\[\\]\\-+\\u2E80-\\u9FFF_]+)";
+  private static final String ID_MATCHER = "([a-zA-Z0-9/\"[ 
],:@#$%&{}\\[\\]\\-+\\u2E80-\\u9FFF_]+)";
 
   private static final String STORAGE_GROUP_MATCHER = 
"([a-zA-Z0-9_.\\u2E80-\\u9FFF]+)";
 
@@ -58,11 +58,14 @@ 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 to match the rule of antlr grammar
   private static final String NODE_MATCHER =
-      "[" + PATH_SEPARATOR + "]([\"])?" + ID_MATCHER + "(" + 
PARTIAL_NODE_MATCHER + ")*([\"])?";
+      "([" + PATH_SEPARATOR + "][\"])?" + ID_MATCHER + "(" + 
PARTIAL_NODE_MATCHER + ")*([\"])?";
 
   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 0b549f5..762d154 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
@@ -201,6 +201,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
@@ -247,6 +248,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));
+    }
+  }
+
   //check if sdt parameters are valid
   private void checkSDTFormat(String path, Map<String, String> props) throws 
IllegalParameterOfPathException {
     if (!props.containsKey(SDT_COMP_DEV)) {
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) {
diff --git 
a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBDeletionIT.java 
b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBDeletionIT.java
index 2ecc041..3dcd6a7 100644
--- a/server/src/test/java/org/apache/iotdb/db/integration/IoTDBDeletionIT.java
+++ b/server/src/test/java/org/apache/iotdb/db/integration/IoTDBDeletionIT.java
@@ -29,7 +29,6 @@ import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Locale;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
-import org.apache.iotdb.db.engine.compaction.CompactionStrategy;
 import org.apache.iotdb.db.utils.EnvironmentUtils;
 import org.apache.iotdb.jdbc.Config;
 import org.junit.After;
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..388b31f 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
@@ -33,7 +33,6 @@ import java.util.stream.Collectors;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.exception.metadata.IllegalPathException;
 import org.apache.iotdb.db.exception.metadata.MetadataException;
-import org.apache.iotdb.db.exception.query.PathException;
 import org.apache.iotdb.db.service.IoTDB;
 import org.apache.iotdb.db.utils.EnvironmentUtils;
 import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
@@ -365,6 +364,58 @@ public class MManagerBasicTest {
   }
 
   @Test
+  public void testSetStorageGroupWithIllegalName() {
+    MManager manager = IoTDB.metaManager;
+    try {
+      PartialPath path1 = new PartialPath("root.laptop\n");
+      try {
+        manager.setStorageGroup(path1);
+        fail();
+      } catch (MetadataException e) {
+      }
+    } catch (IllegalPathException e1) {
+      fail();
+    }
+    try {
+      PartialPath path2 = new PartialPath("root.laptop\t");
+      try {
+        manager.setStorageGroup(path2);
+        fail();
+      } catch (MetadataException e) {
+      }
+    } catch (IllegalPathException e1) {
+      fail();
+    }
+  }
+
+  @Test
+  public void testCreateTimeseriesWithIllegalName() {
+    MManager manager = IoTDB.metaManager;
+    try {
+      PartialPath path1 = new PartialPath("root.laptop.d1\n.s1");
+      try {
+        manager.createTimeseries(path1, TSDataType.INT32, TSEncoding.PLAIN,
+            CompressionType.SNAPPY, null);
+        fail();
+      } catch (MetadataException e) {
+      }
+    } catch (IllegalPathException e1) {
+      fail();
+    }
+    try {
+      PartialPath path2 = new PartialPath("root.laptop.d1\t.s1");
+      try {
+        manager.createTimeseries(path2, TSDataType.INT32, TSEncoding.PLAIN,
+            CompressionType.SNAPPY, null);
+        fail();
+      } catch (MetadataException e) {
+      }
+    } catch (IllegalPathException e1) {
+      fail();
+    }
+  }
+
+  @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");

Reply via email to