You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ge...@apache.org on 2020/07/27 09:19:07 UTC

[incubator-iotdb] branch optimize_path updated: fix bugs

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

geniuspig pushed a commit to branch optimize_path
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/optimize_path by this push:
     new e8eeea6  fix bugs
     new 661cd91  Merge pull request #1567 from Alima777/optimize_path
e8eeea6 is described below

commit e8eeea6ca6848e26184d9528d1b5ed9300fd36fe
Author: Xiangwei Wei <52...@qq.com>
AuthorDate: Mon Jul 27 17:17:12 2020 +0800

    fix bugs
---
 .../org/apache/iotdb/db/engine/StorageEngine.java  |   2 +-
 .../org/apache/iotdb/db/metadata/MetaUtils.java    |  31 ++++++-
 .../apache/iotdb/db/qp/executor/PlanExecutor.java  |   9 +-
 .../org/apache/iotdb/db/service/TSServiceImpl.java | 103 +++++++++++++--------
 .../org/apache/iotdb/session/IoTDBSessionIT.java   |   8 +-
 5 files changed, 105 insertions(+), 48 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java b/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java
index 17d1b88..04fc8fe 100644
--- a/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java
+++ b/server/src/main/java/org/apache/iotdb/db/engine/StorageEngine.java
@@ -275,7 +275,7 @@ public class StorageEngine implements IService {
     String storageGroupName;
     try {
       storageGroupNodes = IoTDB.metaManager.getStorageGroupNameNodes(nodes);
-      storageGroupName = MetaUtils.getPathByNodes(nodes);
+      storageGroupName = MetaUtils.getPathByNodes(storageGroupNodes);
       StorageGroupProcessor processor;
       processor = processorMap.get(storageGroupName);
       if (processor == null) {
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/MetaUtils.java b/server/src/main/java/org/apache/iotdb/db/metadata/MetaUtils.java
index 8cb3271..36ab19a 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/MetaUtils.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/MetaUtils.java
@@ -22,6 +22,7 @@ import static org.apache.iotdb.db.conf.IoTDBConstant.PATH_WILDCARD;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import org.apache.iotdb.db.conf.IoTDBConstant;
 import org.apache.iotdb.db.exception.metadata.IllegalPathException;
@@ -64,7 +65,35 @@ public class MetaUtils {
   }
 
   public static List<String> getDeviceNodeNames(String path) {
-    return Arrays.asList(path.split(PATH_SEPARATOR));
+    List<String> deviceNodes = new ArrayList<>();
+    Collections.addAll(deviceNodes, path.split(PATH_SEPARATOR));
+    return deviceNodes;
+  }
+
+  public static List<String> splitPathToNodes(String path) throws IllegalPathException {
+    List<String> nodes = new ArrayList<>();
+    int startIndex = 0;
+    for (int i = 0; i < path.length(); i++) {
+      if (path.charAt(i) == '.') {
+        nodes.add(path.substring(startIndex, i));
+        startIndex = i + 1;
+      } else if (path.charAt(i) == '"') {
+        int endIndex = path.indexOf('"', i + 1);
+        if (endIndex != -1 && (endIndex == path.length() - 1 || path.charAt(endIndex + 1) == '.')) {
+          nodes.add(path.substring(startIndex, endIndex + 1));
+          i = endIndex + 1;
+          startIndex = endIndex + 2;
+        } else {
+          throw new IllegalPathException("Illegal path: " + path);
+        }
+      } else if (path.charAt(i) == '\'') {
+        throw new IllegalPathException("Illegal path with single quote: " + path);
+      }
+    }
+    if (startIndex <= path.length() - 1) {
+      nodes.add(path.substring(startIndex));
+    }
+    return nodes;
   }
 
   /**
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 7bf4904..f8876a6 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
@@ -751,13 +751,14 @@ public class PlanExecutor implements IPlanExecutor {
     Set<Path> registeredSeries = new HashSet<>();
     for (ChunkGroupMetadata chunkGroupMetadata : chunkGroupMetadataList) {
       String device = chunkGroupMetadata.getDevice();
-      List<String> nodes = MetaUtils.getDeviceNodeNames(device);
+      List<String> nodes = MetaUtils.splitPathToNodes(device);
       MNode node = null;
       try {
         node = mManager.getDeviceNodeWithAutoCreateAndReadLock(device, nodes, true, sgLevel);
         for (ChunkMetadata chunkMetadata : chunkGroupMetadata.getChunkMetadataList()) {
-          nodes.add(chunkMetadata.getMeasurementUid());
-          Path series = new Path(nodes);
+          List<String> pathNodes = new ArrayList<>(nodes);
+          pathNodes.add(chunkMetadata.getMeasurementUid());
+          Path series = new Path(pathNodes);
           if (!registeredSeries.contains(series)) {
             registeredSeries.add(series);
             MeasurementSchema schema = knownSchemas.get(series);
@@ -769,7 +770,7 @@ public class PlanExecutor implements IPlanExecutor {
             }
             if (!node.hasChild(chunkMetadata.getMeasurementUid())) {
               mManager.createTimeseries(
-                  Arrays.asList(),
+                  pathNodes,
                   schema.getType(),
                   schema.getEncodingType(),
                   schema.getCompressor(),
diff --git a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
index 98c1ac8..1680476 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
@@ -50,10 +50,12 @@ import org.apache.iotdb.db.cost.statistic.Operation;
 import org.apache.iotdb.db.exception.BatchInsertionException;
 import org.apache.iotdb.db.exception.QueryInBatchStatementException;
 import org.apache.iotdb.db.exception.StorageEngineException;
+import org.apache.iotdb.db.exception.metadata.IllegalPathException;
 import org.apache.iotdb.db.exception.metadata.MetadataException;
 import org.apache.iotdb.db.exception.metadata.StorageGroupNotSetException;
 import org.apache.iotdb.db.exception.query.QueryProcessException;
 import org.apache.iotdb.db.exception.runtime.SQLParserException;
+import org.apache.iotdb.db.metadata.MetaUtils;
 import org.apache.iotdb.db.metrics.server.SqlArgument;
 import org.apache.iotdb.db.qp.Planner;
 import org.apache.iotdb.db.qp.constant.SQLConstant;
@@ -1128,7 +1130,11 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
     for (int i = 0; i < req.deviceIds.size(); i++) {
       try {
         plan.setDeviceId(req.getDeviceIds().get(i));
-        plan.setDeviceNodes(splitPathToNodes(req.getDeviceIds().get(i)));
+        try {
+          plan.setDeviceNodes(MetaUtils.splitPathToNodes(req.getDeviceIds().get(i)));
+        } catch (IllegalPathException e) {
+          return RpcUtils.getStatus(TSStatusCode.PATH_ILLEGAL, e.getMessage());
+        }
         plan.setTime(req.getTimestamps().get(i));
         plan.setMeasurements(req.getMeasurementsList().get(i).toArray(new String[0]));
         plan.setDataTypes(new TSDataType[plan.getMeasurements().length]);
@@ -1167,7 +1173,11 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
     for (int i = 0; i < req.deviceIds.size(); i++) {
       try {
         plan.setDeviceId(req.getDeviceIds().get(i));
-        plan.setDeviceNodes(splitPathToNodes(req.getDeviceIds().get(i)));
+        try {
+          plan.setDeviceNodes(MetaUtils.splitPathToNodes(req.getDeviceIds().get(i)));
+        } catch (IllegalPathException e) {
+          return RpcUtils.getStatus(TSStatusCode.PATH_ILLEGAL, e.getMessage());
+        }
         plan.setTime(req.getTimestamps().get(i));
         plan.setMeasurements(req.getMeasurementsList().get(i).toArray(new String[0]));
         plan.setDataTypes(new TSDataType[plan.getMeasurements().length]);
@@ -1238,7 +1248,11 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
 
       InsertRowPlan plan = new InsertRowPlan();
       plan.setDeviceId(req.getDeviceId());
-      plan.setDeviceNodes(splitPathToNodes(req.getDeviceId()));
+      try {
+        plan.setDeviceNodes(MetaUtils.splitPathToNodes(req.getDeviceId()));
+      } catch (IllegalPathException e) {
+        return RpcUtils.getStatus(TSStatusCode.PATH_ILLEGAL, e.getMessage());
+      }
       plan.setTime(req.getTimestamp());
       plan.setMeasurements(req.getMeasurements().toArray(new String[0]));
       plan.setDataTypes(new TSDataType[plan.getMeasurements().length]);
@@ -1270,7 +1284,11 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
 
       InsertRowPlan plan = new InsertRowPlan();
       plan.setDeviceId(req.getDeviceId());
-      plan.setDeviceNodes(splitPathToNodes(req.getDeviceId()));
+      try {
+        plan.setDeviceNodes(MetaUtils.splitPathToNodes(req.getDeviceId()));
+      } catch (IllegalPathException e) {
+        return RpcUtils.getStatus(TSStatusCode.PATH_ILLEGAL, e.getMessage());
+      }
       plan.setTime(req.getTimestamp());
       plan.setMeasurements(req.getMeasurements().toArray(new String[0]));
       plan.setDataTypes(new TSDataType[plan.getMeasurements().length]);
@@ -1300,7 +1318,11 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
     plan.setDeleteEndTime(req.getEndTime());
     List<Path> paths = new ArrayList<>();
     for (String path : req.getPaths()) {
-      paths.add(new Path(splitPathToNodes(path)));
+      try {
+        paths.add(new Path(MetaUtils.splitPathToNodes(path)));
+      } catch (IllegalPathException e) {
+        return RpcUtils.getStatus(TSStatusCode.PATH_ILLEGAL, e.getMessage());
+      }
     }
     plan.addPaths(paths);
 
@@ -1321,7 +1343,11 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
       }
 
       InsertTabletPlan insertTabletPlan = new InsertTabletPlan(req.deviceId, req.measurements);
-      insertTabletPlan.setDeviceNodes(splitPathToNodes(req.deviceId));
+      try {
+        insertTabletPlan.setDeviceNodes(MetaUtils.splitPathToNodes(req.deviceId));
+      } catch (IllegalPathException e) {
+        return RpcUtils.getStatus(TSStatusCode.PATH_ILLEGAL, e.getMessage());
+      }
       insertTabletPlan.setTimes(QueryDataSetUtils.readTimesFromBuffer(req.timestamps, req.size));
       insertTabletPlan.setColumns(
           QueryDataSetUtils.readValuesFromBuffer(
@@ -1357,7 +1383,11 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
       for (int i = 0; i < req.deviceIds.size(); i++) {
         InsertTabletPlan insertTabletPlan = new InsertTabletPlan(req.deviceIds.get(i),
             req.measurementsList.get(i));
-        insertTabletPlan.setDeviceNodes(splitPathToNodes(req.deviceIds.get(i)));
+        try {
+          insertTabletPlan.setDeviceNodes(MetaUtils.splitPathToNodes(req.deviceIds.get(i)));
+        } catch (IllegalPathException e) {
+          return RpcUtils.getStatus(TSStatusCode.PATH_ILLEGAL, e.getMessage());
+        }
         insertTabletPlan.setTimes(
             QueryDataSetUtils.readTimesFromBuffer(req.timestampsList.get(i), req.sizeList.get(i)));
         insertTabletPlan.setColumns(
@@ -1391,8 +1421,12 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
       logger.info(INFO_NOT_LOGIN, IoTDBConstant.GLOBAL_DB_NAME);
       return RpcUtils.getStatus(TSStatusCode.NOT_LOGIN_ERROR);
     }
-
-    List<String> storageGroupNodes = splitPathToNodes(storageGroup);
+    List<String> storageGroupNodes;
+    try {
+      storageGroupNodes = MetaUtils.splitPathToNodes(storageGroup);
+    } catch (IllegalPathException e) {
+      return RpcUtils.getStatus(TSStatusCode.PATH_ILLEGAL, e.getMessage());
+    }
     TSStatus status = checkPathValidityWithNodes(storageGroupNodes);
     if (status != null) {
       return status;
@@ -1414,7 +1448,11 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
     }
     List<Path> storageGroupList = new ArrayList<>();
     for (String storageGroup : storageGroups) {
-      storageGroupList.add(new Path(splitPathToNodes(storageGroup)));
+      try {
+        storageGroupList.add(new Path(MetaUtils.splitPathToNodes(storageGroup)));
+      } catch (IllegalPathException e) {
+        return RpcUtils.getStatus(TSStatusCode.PATH_ILLEGAL, e.getMessage());
+      }
     }
     DeleteStorageGroupPlan plan = new DeleteStorageGroupPlan(storageGroupList);
     TSStatus status = checkAuthority(plan, sessionId);
@@ -1434,7 +1472,12 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
     if (auditLogger.isDebugEnabled()) {
       auditLogger.debug("Session-{} create timeseries {}", currSessionId.get(), req.getPath());
     }
-    List<String> seriesNodes = splitPathToNodes(req.path);
+    List<String> seriesNodes;
+    try {
+      seriesNodes = MetaUtils.splitPathToNodes(req.path);
+    } catch (IllegalPathException e) {
+      return RpcUtils.getStatus(TSStatusCode.PATH_ILLEGAL, e.getMessage());
+    }
     TSStatus status = checkPathValidityWithNodes(seriesNodes);
     if (status != null) {
       return status;
@@ -1463,7 +1506,12 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
     }
     List<TSStatus> statusList = new ArrayList<>(req.paths.size());
     for (int i = 0; i < req.paths.size(); i++) {
-      List<String> seriesNodes = splitPathToNodes(req.paths.get(i));
+      List<String> seriesNodes;
+      try {
+        seriesNodes = MetaUtils.splitPathToNodes(req.paths.get(i));
+      } catch (IllegalPathException e) {
+        return RpcUtils.getStatus(TSStatusCode.PATH_ILLEGAL, e.getMessage());
+      }
       CreateTimeSeriesPlan plan = new CreateTimeSeriesPlan(new Path(seriesNodes),
           TSDataType.values()[req.dataTypes.get(i)], TSEncoding.values()[req.encodings.get(i)],
           CompressionType.values()[req.compressors.get(i)],
@@ -1516,7 +1564,11 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
     }
     List<Path> pathList = new ArrayList<>();
     for (String path : paths) {
-      pathList.add(new Path(splitPathToNodes(path)));
+      try {
+        pathList.add(new Path(MetaUtils.splitPathToNodes(path)));
+      } catch (IllegalPathException e) {
+        return RpcUtils.getStatus(TSStatusCode.PATH_ILLEGAL, e.getMessage());
+      }
     }
     DeleteTimeSeriesPlan plan = new DeleteTimeSeriesPlan(pathList);
     TSStatus status = checkAuthority(plan, sessionId);
@@ -1608,29 +1660,4 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
     return SchemaUtils.getSeriesTypesByString(paths, aggregation);
   }
 
-  private List<String> splitPathToNodes(String path) {
-    List<String> nodes = new ArrayList<>();
-    int startIndex = 0;
-    for (int i = 0; i < path.length(); i++) {
-      if (path.charAt(i) == '.') {
-        nodes.add(path.substring(startIndex, i));
-        startIndex = i + 1;
-      } else if (path.charAt(i) == '"') {
-        int endIndex = path.indexOf('"', i + 1);
-        if (endIndex != -1 && (endIndex == path.length() - 1 || path.charAt(endIndex + 1) == '.')) {
-          nodes.add(path.substring(startIndex, endIndex + 1));
-          i = endIndex + 1;
-          startIndex = endIndex + 2;
-        } else {
-          return null;
-        }
-      } else if (path.charAt(i) == '\'') {
-        return null;
-      }
-    }
-    if (startIndex < path.length() - 1) {
-      nodes.add(path.substring(startIndex));
-    }
-    return nodes;
-  }
 }
diff --git a/session/src/test/java/org/apache/iotdb/session/IoTDBSessionIT.java b/session/src/test/java/org/apache/iotdb/session/IoTDBSessionIT.java
index 94c7068..2578d77 100644
--- a/session/src/test/java/org/apache/iotdb/session/IoTDBSessionIT.java
+++ b/session/src/test/java/org/apache/iotdb/session/IoTDBSessionIT.java
@@ -873,7 +873,7 @@ public class IoTDBSessionIT {
   private void queryForAlignByDevice()
       throws StatementExecutionException, IoTDBConnectionException {
     SessionDataSet sessionDataSet = session
-        .executeQueryStatement("select \"11\", s1, \"11\" from root.sg1.d1 align by device");
+        .executeQueryStatement("select '11', s1, '11' from root.sg1.d1 align by device");
     sessionDataSet.setFetchSize(1024);
     int count = 0;
     while (sessionDataSet.hasNext()) {
@@ -883,7 +883,7 @@ public class IoTDBSessionIT {
       for (Field f : fields) {
         sb.append(f.getStringValue()).append(",");
       }
-      Assert.assertEquals("root.sg1.d1,\"11\",0,\"11\",", sb.toString());
+      Assert.assertEquals("root.sg1.d1,'11',0,'11',", sb.toString());
     }
     Assert.assertEquals(1000, count);
     sessionDataSet.closeOperationHandle();
@@ -892,7 +892,7 @@ public class IoTDBSessionIT {
   private void queryForAlignByDevice2()
       throws IoTDBConnectionException, StatementExecutionException {
     SessionDataSet sessionDataSet = session.executeQueryStatement(
-        "select \"11\", s1, \"11\", s5, s1, s5 from root.sg1.d1 align by device");
+        "select '11', s1, '11', s5, s1, s5 from root.sg1.d1 align by device");
     sessionDataSet.setFetchSize(1024);
     int count = 0;
     while (sessionDataSet.hasNext()) {
@@ -902,7 +902,7 @@ public class IoTDBSessionIT {
       for (Field f : fields) {
         sb.append(f.getStringValue()).append(",");
       }
-      Assert.assertEquals("root.sg1.d1,\"11\",0,\"11\",null,0,null,", sb.toString());
+      Assert.assertEquals("root.sg1.d1,'11',0,'11',null,0,null,", sb.toString());
     }
     Assert.assertEquals(1000, count);
     sessionDataSet.closeOperationHandle();