samperson1997 commented on a change in pull request #1705:
URL: https://github.com/apache/incubator-iotdb/pull/1705#discussion_r485630160



##########
File path: server/src/main/java/org/apache/iotdb/db/metadata/MTree.java
##########
@@ -695,6 +708,38 @@ private int getCount(MNode node, String[] nodes, int idx) 
throws MetadataExcepti
     }
   }
 
+  /**
+   * Traverse the MTree to get the count of devices.
+   */
+  private int getDevicesCount(MNode node, String[] nodes, int idx) throws 
MetadataException {
+    String nodeReg = MetaUtils.getNodeRegByIdx(idx, nodes);
+    int cnt = 0;
+    if (!(PATH_WILDCARD).equals(nodeReg)) {
+      if (node.hasChild(nodeReg)) {
+        if (node.getChild(nodeReg) instanceof MeasurementMNode && idx >= 
nodes.length) {
+          cnt++;
+        } else {
+          cnt += getDevicesCount(node.getChild(nodeReg), nodes, idx + 1);
+        }
+      }
+    } else {
+      boolean deviceAdded = false;
+      for (MNode child : node.getChildren().values()) {
+        if (child instanceof MeasurementMNode) {
+          if (!deviceAdded) {
+            cnt++;
+            deviceAdded = true;
+          } else {
+            break;
+          }
+        } else {
+          cnt += getDevicesCount(child, nodes, idx + 1);
+        }
+      }

Review comment:
       Ah.. good point. Maybe @yhwang-hbl could add a specific test case for 
this example ; )




----------------------------------------------------------------
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.

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


Reply via email to