You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2021/11/11 14:39:30 UTC

[GitHub] [iotdb] zyk990424 commented on a change in pull request #4355: Adapt serialization/deserialization in CreateTemplatePlan with former template structure

zyk990424 commented on a change in pull request #4355:
URL: https://github.com/apache/iotdb/pull/4355#discussion_r747551681



##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/template/Template.java
##########
@@ -240,22 +218,25 @@ private void constructTemplateTree(String[] alignedPaths, IMeasurementSchema[] s
 
       measurementNames.add(pathNodes[pathNodes.length - 1]);
     }
-    // find and assign common parent node of aligned measurements to commonPar
-    if (prefix.equals("")) {
-      commonPar = (IEntityMNode) templateRoot;
-    } else {
-      commonPar = (IEntityMNode) constructEntityPath(alignedPaths[0]);
-    }
 
     synchronized (this) {
+      // if not aligned now, it will be set to aligned
       if (!alignedPrefix.contains(prefix)) {
         alignedPrefix.add(prefix);
       }
       for (int i = 0; i <= measurementNames.size() - 1; i++) {
-        leafNode =
-            MeasurementMNode.getMeasurementMNode(
-                commonPar, measurementNames.get(i), schemas[i], "");
-        commonPar.addChild(leafNode);
+        // find the parent and add nodes to template
+        if (prefix.equals("")) {
+          leafNode =
+              MeasurementMNode.getMeasurementMNode(null, measurementNames.get(i), schemas[i], "");
+          directNodes.put(leafNode.getName(), leafNode);
+        } else {
+          commonPar = (IEntityMNode) constructEntityPath(alignedPaths[0]);
+          leafNode =
+              MeasurementMNode.getMeasurementMNode(
+                  commonPar, measurementNames.get(i), schemas[i], "");
+          commonPar.addChild(leafNode);
+        }

Review comment:
       Why set alias "". If there's no alias, it should just be set to null.

##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/template/Template.java
##########
@@ -412,90 +385,81 @@ public boolean isPathExistInTemplate(String path) throws IllegalPathException {
   }
 
   public boolean isDirectNodeInTemplate(String nodeName) {
-    if (templateRoot.hasChild(nodeName)) {
-      return true;
-    } else {
-      return false;
-    }
+    return directNodes.containsKey(nodeName);
   }
 
   public boolean isPathMeasurement(String path) throws IllegalPathException {
     String[] pathNodes = MetaUtils.splitPathToDetachedPath(path);
-    IMNode cur = templateRoot;
-    for (String node : pathNodes) {
-      if (cur.hasChild(node)) {
-        cur = cur.getChild(node);
-      } else return false;
+    if (!directNodes.containsKey(pathNodes[0])) {
+      throw new IllegalPathException(path, "Path does not exist.");
     }

Review comment:
       There's PathNotExistException. May use this is better.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org