You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by xi...@apache.org on 2022/05/12 12:26:12 UTC

[iotdb] branch master updated: Fix path overlap judgement while doing logical plan for schema fetch (#5875)

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

xingtanzjr 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 3d236973bb Fix path overlap judgement while doing logical plan for schema fetch (#5875)
3d236973bb is described below

commit 3d236973bb70dd923094141672dd428c39257037
Author: Marcos_Zyk <38...@users.noreply.github.com>
AuthorDate: Thu May 12 20:26:06 2022 +0800

    Fix path overlap judgement while doing logical plan for schema fetch (#5875)
---
 .../org/apache/iotdb/commons/path/PartialPath.java | 26 ++++++
 .../apache/iotdb/commons/path/PartialPathTest.java | 46 ++++++++++
 .../apache/iotdb/commons/utils/PathUtilsTest.java  | 72 +---------------
 .../db/mpp/common/schematree/PathPatternTree.java  |  2 +-
 .../apache/iotdb/db/metadata/MetaUtilsTest.java    | 98 ----------------------
 5 files changed, 75 insertions(+), 169 deletions(-)

diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/path/PartialPath.java b/node-commons/src/main/java/org/apache/iotdb/commons/path/PartialPath.java
index 89aeecb6bc..b11810e8e6 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/path/PartialPath.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/path/PartialPath.java
@@ -307,6 +307,32 @@ public class PartialPath extends Path implements Comparable<Path>, Cloneable {
     return true;
   }
 
+  /**
+   * Test if this path pattern overlaps with input path pattern. Overlap means the result sets
+   * generated by two path pattern share some common elements. e.g. "root.sg.**" overlaps with
+   * "root.**", "root.*.d.s" overlaps with "root.sg.d.s", "root.sg.**" overlaps with "root.**.s",
+   * "root.*.d.s" doesn't overlap with "root.sg.d1.*"
+   *
+   * @param rPath a plain full path of a timeseries
+   * @return true if a successful match, otherwise return false
+   */
+  public boolean overlapWith(PartialPath rPath) {
+    String[] rNodes = rPath.getNodes();
+    for (int i = 0; i < this.nodes.length && i < rNodes.length; i++) {
+      if (nodes[i].equals(MULTI_LEVEL_PATH_WILDCARD)
+          || rNodes[i].equals(MULTI_LEVEL_PATH_WILDCARD)) {
+        return true;
+      }
+      if (nodes[i].equals(ONE_LEVEL_PATH_WILDCARD) || rNodes[i].equals(ONE_LEVEL_PATH_WILDCARD)) {
+        continue;
+      }
+      if (!nodes[i].equals(rNodes[i])) {
+        return false;
+      }
+    }
+    return this.nodes.length == rNodes.length;
+  }
+
   @Override
   public String getFullPath() {
     if (fullPath == null) {
diff --git a/node-commons/src/test/java/org/apache/iotdb/commons/path/PartialPathTest.java b/node-commons/src/test/java/org/apache/iotdb/commons/path/PartialPathTest.java
new file mode 100644
index 0000000000..babcf9262c
--- /dev/null
+++ b/node-commons/src/test/java/org/apache/iotdb/commons/path/PartialPathTest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.commons.path;
+
+import org.apache.iotdb.commons.exception.IllegalPathException;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PartialPathTest {
+
+  @Test
+  public void testOverlapWith() throws IllegalPathException {
+    PartialPath[][] pathPairs =
+        new PartialPath[][] {
+          new PartialPath[] {new PartialPath("root.**"), new PartialPath("root.sg.**")},
+          new PartialPath[] {new PartialPath("root.**.*"), new PartialPath("root.sg.**")},
+          new PartialPath[] {new PartialPath("root.**.s"), new PartialPath("root.sg.**")},
+          new PartialPath[] {new PartialPath("root.*.**"), new PartialPath("root.sg.**")},
+          new PartialPath[] {new PartialPath("root.*.d.s"), new PartialPath("root.**.s")},
+          new PartialPath[] {new PartialPath("root.*.d.s"), new PartialPath("root.sg.*.s")},
+          new PartialPath[] {new PartialPath("root.*.d.s"), new PartialPath("root.sg.d2.s")},
+          new PartialPath[] {new PartialPath("root.*.d.s.*"), new PartialPath("root.sg.d.s")}
+        };
+    boolean[] results = new boolean[] {true, true, true, true, true, true, false, false};
+    for (int i = 0; i < pathPairs.length; i++) {
+      Assert.assertEquals(results[i], pathPairs[i][0].overlapWith(pathPairs[i][1]));
+    }
+  }
+}
diff --git a/server/src/test/java/org/apache/iotdb/db/metadata/MetaUtilsTest.java b/node-commons/src/test/java/org/apache/iotdb/commons/utils/PathUtilsTest.java
similarity index 60%
copy from server/src/test/java/org/apache/iotdb/db/metadata/MetaUtilsTest.java
copy to node-commons/src/test/java/org/apache/iotdb/commons/utils/PathUtilsTest.java
index 1e8ddb51b8..1e73e04b99 100644
--- a/server/src/test/java/org/apache/iotdb/db/metadata/MetaUtilsTest.java
+++ b/node-commons/src/test/java/org/apache/iotdb/commons/utils/PathUtilsTest.java
@@ -16,29 +16,19 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.iotdb.db.metadata;
+package org.apache.iotdb.commons.utils;
 
 import org.apache.iotdb.commons.exception.IllegalPathException;
-import org.apache.iotdb.commons.exception.MetadataException;
-import org.apache.iotdb.commons.path.PartialPath;
-import org.apache.iotdb.commons.utils.PathUtils;
-import org.apache.iotdb.db.metadata.mnode.InternalMNode;
-import org.apache.iotdb.db.metadata.path.AlignedPath;
-import org.apache.iotdb.db.metadata.path.MeasurementPath;
-import org.apache.iotdb.db.metadata.utils.MetaUtils;
 
 import org.junit.Assert;
 import org.junit.Test;
 
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.List;
 
 import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-public class MetaUtilsTest {
+public class PathUtilsTest {
 
   @Test
   public void testSplitPathToNodes() throws IllegalPathException {
@@ -132,62 +122,4 @@ public class MetaUtilsTest {
       Assert.assertEquals("root.sg.d1. is not a legal path", e.getMessage());
     }
   }
-
-  @Test
-  public void testGetMultiFullPaths() {
-    InternalMNode rootNode = new InternalMNode(null, "root");
-
-    // builds the relationship of root.a and root.aa
-    InternalMNode aNode = new InternalMNode(rootNode, "a");
-    rootNode.addChild(aNode.getName(), aNode);
-    InternalMNode aaNode = new InternalMNode(rootNode, "aa");
-    rootNode.addChild(aaNode.getName(), aaNode);
-
-    // builds the relationship of root.a.b and root.aa.bb
-    InternalMNode bNode = new InternalMNode(aNode, "b");
-    aNode.addChild(bNode.getName(), bNode);
-    InternalMNode bbNode = new InternalMNode(aaNode, "bb");
-    aaNode.addChild(bbNode.getName(), bbNode);
-
-    // builds the relationship of root.aa.bb.cc
-    InternalMNode ccNode = new InternalMNode(bbNode, "cc");
-    bbNode.addChild(ccNode.getName(), ccNode);
-
-    List<String> multiFullPaths = MetaUtils.getMultiFullPaths(rootNode);
-    Assert.assertSame(2, multiFullPaths.size());
-
-    multiFullPaths.forEach(
-        fullPath -> {
-          if (fullPath.contains("aa")) {
-            Assert.assertEquals("root.aa.bb.cc", fullPath);
-          } else {
-            Assert.assertEquals("root.a.b", fullPath);
-          }
-        });
-  }
-
-  @Test
-  public void testGroupAlignedPath() throws MetadataException {
-    List<PartialPath> pathList = new ArrayList<>();
-
-    MeasurementPath path1 = new MeasurementPath(new PartialPath("root.sg.device.s1"), null);
-    pathList.add(path1);
-    MeasurementPath path2 = new MeasurementPath(new PartialPath("root.sg.device.s2"), null);
-    pathList.add(path2);
-
-    MeasurementPath path3 = new MeasurementPath(new PartialPath("root.sg.aligned_device.s1"), null);
-    path3.setUnderAlignedEntity(true);
-    pathList.add(path3);
-    MeasurementPath path4 = new MeasurementPath(new PartialPath("root.sg.aligned_device.s2"), null);
-    path4.setUnderAlignedEntity(true);
-    pathList.add(path4);
-
-    AlignedPath alignedPath = new AlignedPath(path3);
-    alignedPath.addMeasurement(path4);
-
-    List<PartialPath> result = MetaUtils.groupAlignedPaths(pathList);
-    assertTrue(result.contains(path1));
-    assertTrue(result.contains(path2));
-    assertTrue(result.contains(alignedPath));
-  }
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/PathPatternTree.java b/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/PathPatternTree.java
index d7e70aea7e..8f3a78c498 100644
--- a/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/PathPatternTree.java
+++ b/server/src/main/java/org/apache/iotdb/db/mpp/common/schematree/PathPatternTree.java
@@ -259,7 +259,7 @@ public class PathPatternTree {
     PartialPath pattern = prefixPath.concatNode(MULTI_LEVEL_PATH_WILDCARD);
     List<PartialPath> involvedPath = new ArrayList<>();
     for (PartialPath path : pathList) {
-      if (pattern.matchFullPath(path) || path.matchFullPath(pattern)) {
+      if (pattern.overlapWith(path)) {
         involvedPath.add(path);
       }
     }
diff --git a/server/src/test/java/org/apache/iotdb/db/metadata/MetaUtilsTest.java b/server/src/test/java/org/apache/iotdb/db/metadata/MetaUtilsTest.java
index 1e8ddb51b8..6b83212a5e 100644
--- a/server/src/test/java/org/apache/iotdb/db/metadata/MetaUtilsTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/metadata/MetaUtilsTest.java
@@ -18,10 +18,8 @@
  */
 package org.apache.iotdb.db.metadata;
 
-import org.apache.iotdb.commons.exception.IllegalPathException;
 import org.apache.iotdb.commons.exception.MetadataException;
 import org.apache.iotdb.commons.path.PartialPath;
-import org.apache.iotdb.commons.utils.PathUtils;
 import org.apache.iotdb.db.metadata.mnode.InternalMNode;
 import org.apache.iotdb.db.metadata.path.AlignedPath;
 import org.apache.iotdb.db.metadata.path.MeasurementPath;
@@ -31,108 +29,12 @@ import org.junit.Assert;
 import org.junit.Test;
 
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 
-import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 public class MetaUtilsTest {
 
-  @Test
-  public void testSplitPathToNodes() throws IllegalPathException {
-    assertArrayEquals(
-        Arrays.asList("root", "sg", "d1", "s1").toArray(),
-        PathUtils.splitPathToDetachedPath("root.sg.d1.s1"));
-
-    assertArrayEquals(
-        Arrays.asList("root", "sg", "d1", "s+1").toArray(),
-        PathUtils.splitPathToDetachedPath("root.sg.d1.`s+1`"));
-
-    assertArrayEquals(
-        Arrays.asList("root", "\"s g\"", "d1", "\"s+1\"").toArray(),
-        PathUtils.splitPathToDetachedPath("root.`\"s g\"`.d1.`\"s+1\"`"));
-
-    assertArrayEquals(
-        Arrays.asList("root", "1").toArray(), PathUtils.splitPathToDetachedPath("root.1"));
-
-    assertArrayEquals(
-        Arrays.asList("root", "sg", "d1", "s", "1").toArray(),
-        PathUtils.splitPathToDetachedPath("root.sg.d1.s.1"));
-
-    assertArrayEquals(
-        Arrays.asList("root", "sg", "d1", "`a.b`").toArray(),
-        PathUtils.splitPathToDetachedPath("root.sg.d1.```a.b```"));
-
-    assertArrayEquals(
-        Arrays.asList("root", "sg", "d1", "`").toArray(),
-        PathUtils.splitPathToDetachedPath("root.sg.d1.````"));
-
-    assertArrayEquals(
-        Arrays.asList("root", "sg", "d1", "`").toArray(),
-        PathUtils.splitPathToDetachedPath("`root`.`sg`.`d1`.````"));
-
-    assertArrayEquals(
-        Arrays.asList("root", "sg", "d1", "`").toArray(),
-        PathUtils.splitPathToDetachedPath("`root`.sg.`d1`.````"));
-
-    assertArrayEquals(
-        Arrays.asList("root", "sg", "d1.`").toArray(),
-        PathUtils.splitPathToDetachedPath("root.sg.`d1.```"));
-
-    assertArrayEquals(
-        Arrays.asList("root", "sg", "\"d").toArray(),
-        PathUtils.splitPathToDetachedPath("root.sg.`\\\"d`"));
-
-    assertArrayEquals(
-        Arrays.asList("root", "sg", "\td").toArray(),
-        PathUtils.splitPathToDetachedPath("root.sg.`\\td`"));
-
-    assertArrayEquals(
-        Arrays.asList("root", "sg", "\\td").toArray(),
-        PathUtils.splitPathToDetachedPath("root.sg.`\\\\td`"));
-
-    assertArrayEquals(
-        Arrays.asList("root", "laptop", "d1", "\"1.2.3\"").toArray(),
-        PathUtils.splitPathToDetachedPath("root.laptop.d1.`\\\"1.2.3\\\"`"));
-
-    try {
-      PathUtils.splitPathToDetachedPath("root.sg.d1.```");
-      fail();
-    } catch (IllegalPathException e) {
-      Assert.assertEquals("root.sg.d1.``` is not a legal path", e.getMessage());
-    }
-
-    try {
-      PathUtils.splitPathToDetachedPath("root.sg.`d1`..`aa``b`");
-      fail();
-    } catch (IllegalPathException e) {
-      Assert.assertEquals("root.sg.`d1`..`aa``b` is not a legal path", e.getMessage());
-    }
-
-    try {
-      PathUtils.splitPathToDetachedPath("root.sg.d1.`s+`-1\"`");
-      fail();
-    } catch (IllegalPathException e) {
-      Assert.assertEquals("root.sg.d1.`s+`-1\"` is not a legal path", e.getMessage());
-    }
-
-    try {
-      PathUtils.splitPathToDetachedPath("root..a");
-      fail();
-    } catch (IllegalPathException e) {
-      Assert.assertEquals("root..a is not a legal path", e.getMessage());
-    }
-
-    try {
-      PathUtils.splitPathToDetachedPath("root.sg.d1.");
-      fail();
-    } catch (IllegalPathException e) {
-      Assert.assertEquals("root.sg.d1. is not a legal path", e.getMessage());
-    }
-  }
-
   @Test
   public void testGetMultiFullPaths() {
     InternalMNode rootNode = new InternalMNode(null, "root");