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 2020/09/09 02:15:30 UTC

[GitHub] [incubator-iotdb] neuyilan commented on a change in pull request #1705: [IOTDB-873] Add count devices DDL

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



##########
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{

Review comment:
       code format
   }else{- > } else {
   if( !deviceAdded){. -> if( !deviceAdded) {
   
   please use google style format: http://iotdb.apache.org/zh/Development/ContributeGuide.html




----------------------------------------------------------------
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:
users@infra.apache.org