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/16 02:21:28 UTC

[GitHub] [iotdb] zyk990424 commented on a change in pull request #4391: [IOTDB-1931] Adapt tree structrued Template with MManager

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



##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/mtree/traverser/Traverser.java
##########
@@ -221,27 +235,77 @@ protected void processNameMatch(IMNode node, int idx, int level) throws Metadata
     }
 
     Template upperTemplate = node.getUpperTemplate();
-    IMeasurementSchema targetSchema = upperTemplate.getSchemaMap().get(targetName);
-    if (targetSchema != null) {
-      traverse(
-          MeasurementMNode.getMeasurementMNode(
-              node.getAsEntityMNode(), targetSchema.getMeasurementId(), targetSchema, null),
-          idx + 1,
-          level + 1);
+
+    IMNode targetNode = upperTemplate.getDirectNode(targetName);
+    if (targetNode != null) {
+      traverseContext.push(node);
+      traverse(targetNode, idx + 1, level + 1);
+      traverseContext.pop();
     }
 
     if (multiLevelWildcard) {
-      for (IMeasurementSchema schema : upperTemplate.getSchemaMap().values()) {
-        traverse(
-            MeasurementMNode.getMeasurementMNode(
-                node.getAsEntityMNode(), schema.getMeasurementId(), schema, null),
-            idx,
-            level + 1);
+      for (IMNode child : upperTemplate.getDirectNodes()) {
+        traverseContext.push(node);
+        traverse(child, idx, level + 1);
+        traverseContext.pop();
       }
     }
   }
 
   public void setPrefixMatch(boolean isPrefixMatch) {
     this.isPrefixMatch = isPrefixMatch;
   }
+
+  /**
+   * @param currentNode the node need to get the full path of
+   * @return full path from traverse start node to the current node
+   */
+  protected PartialPath getPivotPartialPath(IMNode currentNode) throws IllegalPathException {
+    Iterator<IMNode> nodes = traverseContext.descendingIterator();
+    StringBuilder builder = new StringBuilder(nodes.next().getName());
+    while (nodes.hasNext()) {
+      builder.append(TsFileConstant.PATH_SEPARATOR);
+      builder.append(nodes.next().getName());
+    }
+    if (builder.length() != 0) {
+      builder.append(TsFileConstant.PATH_SEPARATOR);
+    }
+    builder.append(currentNode.getName());
+    return new PartialPath(builder.toString());
+  }
+
+  protected MeasurementPath getPivotMeasurementPathInTraverse(IMeasurementMNode currentNode)
+      throws MetadataException {
+    IMNode par = traverseContext.peek();
+    if (!(par instanceof IEntityMNode)) {
+      throw new MetadataException("Measurement not under entity: " + currentNode.getName());
+    }

Review comment:
       Is this necessary? How could the parent MNode of current MeasurementMNode not be Entity?

##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/mtree/traverser/Traverser.java
##########
@@ -221,27 +235,77 @@ protected void processNameMatch(IMNode node, int idx, int level) throws Metadata
     }
 
     Template upperTemplate = node.getUpperTemplate();
-    IMeasurementSchema targetSchema = upperTemplate.getSchemaMap().get(targetName);
-    if (targetSchema != null) {
-      traverse(
-          MeasurementMNode.getMeasurementMNode(
-              node.getAsEntityMNode(), targetSchema.getMeasurementId(), targetSchema, null),
-          idx + 1,
-          level + 1);
+
+    IMNode targetNode = upperTemplate.getDirectNode(targetName);
+    if (targetNode != null) {
+      traverseContext.push(node);
+      traverse(targetNode, idx + 1, level + 1);
+      traverseContext.pop();
     }
 
     if (multiLevelWildcard) {
-      for (IMeasurementSchema schema : upperTemplate.getSchemaMap().values()) {
-        traverse(
-            MeasurementMNode.getMeasurementMNode(
-                node.getAsEntityMNode(), schema.getMeasurementId(), schema, null),
-            idx,
-            level + 1);
+      for (IMNode child : upperTemplate.getDirectNodes()) {
+        traverseContext.push(node);
+        traverse(child, idx, level + 1);
+        traverseContext.pop();
       }
     }
   }
 
   public void setPrefixMatch(boolean isPrefixMatch) {
     this.isPrefixMatch = isPrefixMatch;
   }
+
+  /**
+   * @param currentNode the node need to get the full path of
+   * @return full path from traverse start node to the current node
+   */
+  protected PartialPath getPivotPartialPath(IMNode currentNode) throws IllegalPathException {
+    Iterator<IMNode> nodes = traverseContext.descendingIterator();
+    StringBuilder builder = new StringBuilder(nodes.next().getName());
+    while (nodes.hasNext()) {
+      builder.append(TsFileConstant.PATH_SEPARATOR);
+      builder.append(nodes.next().getName());
+    }
+    if (builder.length() != 0) {
+      builder.append(TsFileConstant.PATH_SEPARATOR);
+    }
+    builder.append(currentNode.getName());
+    return new PartialPath(builder.toString());
+  }
+
+  protected MeasurementPath getPivotMeasurementPathInTraverse(IMeasurementMNode currentNode)
+      throws MetadataException {
+    IMNode par = traverseContext.peek();
+    if (!(par instanceof IEntityMNode)) {
+      throw new MetadataException("Measurement not under entity: " + currentNode.getName());
+    }

Review comment:
       Avoid instanceof. Use IMNode.isEntity instead.

##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/mtree/traverser/Traverser.java
##########
@@ -221,27 +235,77 @@ protected void processNameMatch(IMNode node, int idx, int level) throws Metadata
     }
 
     Template upperTemplate = node.getUpperTemplate();
-    IMeasurementSchema targetSchema = upperTemplate.getSchemaMap().get(targetName);
-    if (targetSchema != null) {
-      traverse(
-          MeasurementMNode.getMeasurementMNode(
-              node.getAsEntityMNode(), targetSchema.getMeasurementId(), targetSchema, null),
-          idx + 1,
-          level + 1);
+
+    IMNode targetNode = upperTemplate.getDirectNode(targetName);
+    if (targetNode != null) {
+      traverseContext.push(node);
+      traverse(targetNode, idx + 1, level + 1);
+      traverseContext.pop();
     }
 
     if (multiLevelWildcard) {
-      for (IMeasurementSchema schema : upperTemplate.getSchemaMap().values()) {
-        traverse(
-            MeasurementMNode.getMeasurementMNode(
-                node.getAsEntityMNode(), schema.getMeasurementId(), schema, null),
-            idx,
-            level + 1);
+      for (IMNode child : upperTemplate.getDirectNodes()) {
+        traverseContext.push(node);
+        traverse(child, idx, level + 1);
+        traverseContext.pop();
       }
     }
   }
 
   public void setPrefixMatch(boolean isPrefixMatch) {
     this.isPrefixMatch = isPrefixMatch;
   }
+
+  /**
+   * @param currentNode the node need to get the full path of
+   * @return full path from traverse start node to the current node
+   */
+  protected PartialPath getPivotPartialPath(IMNode currentNode) throws IllegalPathException {
+    Iterator<IMNode> nodes = traverseContext.descendingIterator();
+    StringBuilder builder = new StringBuilder(nodes.next().getName());
+    while (nodes.hasNext()) {
+      builder.append(TsFileConstant.PATH_SEPARATOR);
+      builder.append(nodes.next().getName());
+    }
+    if (builder.length() != 0) {
+      builder.append(TsFileConstant.PATH_SEPARATOR);
+    }
+    builder.append(currentNode.getName());
+    return new PartialPath(builder.toString());
+  }
+
+  protected MeasurementPath getPivotMeasurementPathInTraverse(IMeasurementMNode currentNode)
+      throws MetadataException {
+    IMNode par = traverseContext.peek();
+    if (!(par instanceof IEntityMNode)) {
+      throw new MetadataException("Measurement not under entity: " + currentNode.getName());
+    }
+
+    Iterator<IMNode> nodes = traverseContext.descendingIterator();
+    StringBuilder builder = new StringBuilder(nodes.next().getName());
+    while (nodes.hasNext()) {
+      builder.append(TsFileConstant.PATH_SEPARATOR);
+      builder.append(nodes.next().getName());
+    }
+    if (builder.length() != 0) {
+      builder.append(TsFileConstant.PATH_SEPARATOR);
+    }
+    builder.append(currentNode.getName());
+    MeasurementPath retPath =
+        new MeasurementPath(new PartialPath(builder.toString()), currentNode.getSchema());
+    retPath.setUnderAlignedEntity(((IEntityMNode) par).isAligned());
+    return retPath;

Review comment:
       Replace (IEntityMNode) par with par.getAsEntity

##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/mtree/traverser/Traverser.java
##########
@@ -137,20 +146,20 @@ protected abstract boolean processFullMatchedMNode(IMNode node, int idx, int lev
   protected void processMultiLevelWildcard(IMNode node, int idx, int level)
       throws MetadataException {
     for (IMNode child : node.getChildren().values()) {
+      traverseContext.push(node);
       traverse(child, idx + 1, level + 1);
+      traverseContext.pop();
     }

Review comment:
       If  you want to make the context contains node from root to current node's parent, maybe put this push and pop out of the for loop 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