You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ja...@apache.org on 2022/04/28 10:41:14 UTC

[iotdb] branch master updated: fix root.**.* (#5715)

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

jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 3d028a7817 fix root.**.* (#5715)
3d028a7817 is described below

commit 3d028a78174da5f239d149588029f9bbe6ab1e99
Author: Marcos_Zyk <38...@users.noreply.github.com>
AuthorDate: Thu Apr 28 18:41:07 2022 +0800

    fix root.**.* (#5715)
---
 .../db/metadata/tree/AbstractTreeVisitor.java      | 62 ++++++++++++----------
 .../db/mpp/common/schematree/SchemaTreeTest.java   | 51 ++++++++++++++++++
 2 files changed, 84 insertions(+), 29 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/tree/AbstractTreeVisitor.java b/server/src/main/java/org/apache/iotdb/db/metadata/tree/AbstractTreeVisitor.java
index 658a6ebfc3..a7492722b5 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/tree/AbstractTreeVisitor.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/tree/AbstractTreeVisitor.java
@@ -178,10 +178,15 @@ public abstract class AbstractTreeVisitor<N extends ITreeNode, R> implements Ite
           }
 
           if (!isLeafNode(node)) {
-            if (isPrefixMatch) {
-              pushAllChildren(node, patternIndex + 1, lastMultiLevelWildcardIndex);
-            } else if (nodes[patternIndex].equals(MULTI_LEVEL_PATH_WILDCARD)) {
+            if (nodes[patternIndex].equals(MULTI_LEVEL_PATH_WILDCARD)) {
               pushAllChildren(node, patternIndex, patternIndex);
+            } else if (lastMultiLevelWildcardIndex != -1) {
+              pushAllChildren(
+                  node,
+                  findLastMatch(node, patternIndex, lastMultiLevelWildcardIndex) + 1,
+                  lastMultiLevelWildcardIndex);
+            } else if (isPrefixMatch) {
+              pushAllChildren(node, patternIndex + 1, lastMultiLevelWildcardIndex);
             }
           }
 
@@ -211,35 +216,12 @@ public abstract class AbstractTreeVisitor<N extends ITreeNode, R> implements Ite
           }
         }
 
-        if (nextMatchedNode != null) {
-          return;
-        }
-
       } else {
         if (lastMultiLevelWildcardIndex == -1) {
           continue;
         }
 
-        int lastMatchIndex = lastMultiLevelWildcardIndex;
-        for (int i = patternIndex - 1; i > lastMultiLevelWildcardIndex; i--) {
-          if (!checkIsMatch(i, node)) {
-            continue;
-          }
-
-          Iterator<N> ancestors = ancestorStack.iterator();
-          boolean allMatch = true;
-          for (int j = i - 1; j > lastMultiLevelWildcardIndex; j--) {
-            if (!checkIsMatch(j, ancestors.next())) {
-              allMatch = false;
-              break;
-            }
-          }
-
-          if (allMatch) {
-            lastMatchIndex = i;
-            break;
-          }
-        }
+        int lastMatchIndex = findLastMatch(node, patternIndex, lastMultiLevelWildcardIndex);
 
         if (processInternalMatchedNode(node)) {
           return;
@@ -248,12 +230,34 @@ public abstract class AbstractTreeVisitor<N extends ITreeNode, R> implements Ite
         if (!isLeafNode(node)) {
           pushAllChildren(node, lastMatchIndex + 1, lastMultiLevelWildcardIndex);
         }
+      }
 
-        if (nextMatchedNode != null) {
-          return;
+      if (nextMatchedNode != null) {
+        return;
+      }
+    }
+  }
+
+  private int findLastMatch(N node, int patternIndex, int lastMultiLevelWildcardIndex) {
+    for (int i = patternIndex - 1; i > lastMultiLevelWildcardIndex; i--) {
+      if (!checkIsMatch(i, node)) {
+        continue;
+      }
+
+      Iterator<N> ancestors = ancestorStack.iterator();
+      boolean allMatch = true;
+      for (int j = i - 1; j > lastMultiLevelWildcardIndex; j--) {
+        if (!checkIsMatch(j, ancestors.next())) {
+          allMatch = false;
+          break;
         }
       }
+
+      if (allMatch) {
+        return i;
+      }
     }
+    return lastMultiLevelWildcardIndex;
   }
 
   public void reset() {
diff --git a/server/src/test/java/org/apache/iotdb/db/mpp/common/schematree/SchemaTreeTest.java b/server/src/test/java/org/apache/iotdb/db/mpp/common/schematree/SchemaTreeTest.java
index 9f8d6d486d..fc2b5d1250 100644
--- a/server/src/test/java/org/apache/iotdb/db/mpp/common/schematree/SchemaTreeTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/mpp/common/schematree/SchemaTreeTest.java
@@ -112,6 +112,9 @@ public class SchemaTreeTest {
         new SchemaTreeMeasurementVisitor(root, new PartialPath("root.**.d.**.c.s1"), 0, 0, false);
     checkVisitorResult(
         visitor, 1, new String[] {"root.c.c.c.d.c.c.s1"}, null, new boolean[] {false});
+
+    visitor = new SchemaTreeMeasurementVisitor(root, new PartialPath("root.**.d.*.*"), 0, 0, false);
+    checkVisitorResult(visitor, 1, new String[] {"root.c.c.c.d.c.s1"}, null, new boolean[] {false});
   }
 
   private void testSchemaTree(SchemaNode root) throws Exception {
@@ -203,6 +206,54 @@ public class SchemaTreeTest {
         new String[] {"status", "status"},
         new boolean[] {true, false},
         new int[] {2, 3});
+
+    visitor = new SchemaTreeMeasurementVisitor(root, new PartialPath("root.**.*"), 10, 0, false);
+    checkVisitorResult(
+        visitor,
+        6,
+        new String[] {
+          "root.sg.d1.s1",
+          "root.sg.d1.s2",
+          "root.sg.d2.a.s1",
+          "root.sg.d2.a.s2",
+          "root.sg.d2.s1",
+          "root.sg.d2.s2"
+        },
+        new String[] {"", "", "", "", "", ""},
+        new boolean[] {false, false, true, true, false, false},
+        new int[] {1, 2, 3, 4, 5, 6});
+
+    visitor = new SchemaTreeMeasurementVisitor(root, new PartialPath("root.**.*.**"), 10, 0, false);
+    checkVisitorResult(
+        visitor,
+        6,
+        new String[] {
+          "root.sg.d1.s1",
+          "root.sg.d1.s2",
+          "root.sg.d2.a.s1",
+          "root.sg.d2.a.s2",
+          "root.sg.d2.s1",
+          "root.sg.d2.s2"
+        },
+        new String[] {"", "", "", "", "", ""},
+        new boolean[] {false, false, true, true, false, false},
+        new int[] {1, 2, 3, 4, 5, 6});
+
+    visitor = new SchemaTreeMeasurementVisitor(root, new PartialPath("root.*.**.**"), 10, 0, false);
+    checkVisitorResult(
+        visitor,
+        6,
+        new String[] {
+          "root.sg.d1.s1",
+          "root.sg.d1.s2",
+          "root.sg.d2.a.s1",
+          "root.sg.d2.a.s2",
+          "root.sg.d2.s1",
+          "root.sg.d2.s2"
+        },
+        new String[] {"", "", "", "", "", ""},
+        new boolean[] {false, false, true, true, false, false},
+        new int[] {1, 2, 3, 4, 5, 6});
   }
 
   /**