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

zyk 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 a8077c40dd [IOTDB-5243] UT related to timeseries and metadata info 
query (#8564)
a8077c40dd is described below

commit a8077c40ddf44366a76245cf3c991ad765fff805
Author: 橘子 <[email protected]>
AuthorDate: Wed Dec 21 05:08:30 2022 -0800

    [IOTDB-5243] UT related to timeseries and metadata info query (#8564)
    
    [IOTDB-5243] UT related to timeseries and metadata info query (#8564)
---
 .../db/metadata/schemaregion/ISchemaRegion.java    |  62 ++-
 .../schemaRegion/SchemaRegionBasicTest.java        | 435 +++++++++++++++++++++
 .../schemaRegion/SchemaRegionTestUtil.java         |  33 ++
 3 files changed, 528 insertions(+), 2 deletions(-)

diff --git 
a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/ISchemaRegion.java
 
b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/ISchemaRegion.java
index 82c8ba3430..a11e8356f2 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/ISchemaRegion.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/ISchemaRegion.java
@@ -91,10 +91,33 @@ public interface ISchemaRegion {
   // endregion
 
   // region Interfaces for Timeseries operation
+  /**
+   * Create timeseries.
+   *
+   * @param plan a plan describes how to create the timeseries.
+   * @param offset
+   * @throws MetadataException
+   */
   void createTimeseries(ICreateTimeSeriesPlan plan, long offset) throws 
MetadataException;
 
+  /**
+   * Create aligned timeseries.
+   *
+   * @param plan a plan describes how to create the timeseries.
+   * @throws MetadataException
+   */
   void createAlignedTimeSeries(ICreateAlignedTimeSeriesPlan plan) throws 
MetadataException;
 
+  /**
+   * Check whether measurement exists.
+   *
+   * @param devicePath the path of device that you want to check
+   * @param measurementList a list of measurements that you want to check
+   * @param aliasList a list of alias that you want to check
+   * @return returns a map contains index of the measurements or alias that 
threw the exception, and
+   *     exception details. The exceptions describe whether the measurement or 
alias exists. For
+   *     example, a MeasurementAlreadyExistException means this measurement 
exists.
+   */
   Map<Integer, MetadataException> checkMeasurementExistence(
       PartialPath devicePath, List<String> measurementList, List<String> 
aliasList);
 
@@ -150,6 +173,11 @@ public interface ISchemaRegion {
 
   // region Interfaces for metadata count
 
+  /**
+   * To calculate the count of timeseries matching given path. The path could 
be a pattern of a full
+   * path, may contain wildcard. If using prefix match, the path pattern is 
used to match prefix
+   * path. All timeseries start with the matched prefix path will be counted.
+   */
   long getAllTimeseriesCount(
       PartialPath pathPattern, Map<Integer, Template> templateMap, boolean 
isPrefixMatch)
       throws MetadataException;
@@ -158,7 +186,16 @@ public interface ISchemaRegion {
       PartialPath pathPattern, boolean isPrefixMatch, String key, String 
value, boolean isContains)
       throws MetadataException;
 
-  // The measurements will be grouped by the node in given level and then 
counted for each group.
+  /**
+   * The measurements will be grouped by the node in given level and then 
counted for each group. If
+   * no measurements found, but the path is contained in the group, then this 
path will also be
+   * returned with measurements count zero.
+   *
+   * @param pathPattern
+   * @param level the level you want to group by
+   * @param isPrefixMatch using pathPattern as prefix matched path if set true
+   * @return return a map from PartialPath to the count of matched measurements
+   */
   Map<PartialPath, Long> getMeasurementCountGroupByLevel(
       PartialPath pathPattern, int level, boolean isPrefixMatch) throws 
MetadataException;
 
@@ -175,12 +212,23 @@ public interface ISchemaRegion {
    * To calculate the count of devices for given path pattern. If using prefix 
match, the path
    * pattern is used to match prefix path. All timeseries start with the 
matched prefix path will be
    * counted.
+   *
+   * @param pathPattern
+   * @param isPrefixMatch
    */
   long getDevicesNum(PartialPath pathPattern, boolean isPrefixMatch) throws 
MetadataException;
   // endregion
 
   // region Interfaces for level Node info Query
-  // Get paths of nodes in given level and matching the pathPattern.
+  /**
+   * Get paths of nodes in given level and matching the pathPattern.
+   *
+   * @param pathPattern
+   * @param nodeLevel
+   * @param isPrefixMatch
+   * @throws MetadataException
+   * @return returns a list of PartialPath.
+   */
   List<PartialPath> getNodesListInGivenLevel(
       PartialPath pathPattern, int nodeLevel, boolean isPrefixMatch) throws 
MetadataException;
 
@@ -208,6 +256,7 @@ public interface ISchemaRegion {
    * @param isPrefixMatch if true, the path pattern is used to match prefix 
path.
    * @return A HashSet instance which stores devices paths matching the given 
path pattern.
    */
+  @Deprecated
   Set<PartialPath> getMatchedDevices(PartialPath pathPattern, boolean 
isPrefixMatch)
       throws MetadataException;
 
@@ -232,6 +281,7 @@ public interface ISchemaRegion {
    * @param isPrefixMatch if true, the path pattern is used to match prefix 
path
    * @param withTags whether returns tag kvs in the result list.
    */
+  @Deprecated
   List<MeasurementPath> getMeasurementPaths(
       PartialPath pathPattern, boolean isPrefixMatch, boolean withTags) throws 
MetadataException;
 
@@ -242,6 +292,7 @@ public interface ISchemaRegion {
    *
    * @param isPrefixMatch if true, the path pattern is used to match prefix 
path
    */
+  @Deprecated
   Pair<List<MeasurementPath>, Integer> getMeasurementPathsWithAlias(
       PartialPath pathPattern, int limit, int offset, boolean isPrefixMatch, 
boolean withTags)
       throws MetadataException;
@@ -250,6 +301,13 @@ public interface ISchemaRegion {
       PartialPath pathPattern, Map<Integer, Template> templateMap, boolean 
withTags)
       throws MetadataException;
 
+  /**
+   * Show timeseries.
+   *
+   * @param plan
+   * @param context
+   * @throws MetadataException
+   */
   Pair<List<ShowTimeSeriesResult>, Integer> showTimeseries(
       ShowTimeSeriesPlan plan, QueryContext context) throws MetadataException;
   // endregion
diff --git 
a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionBasicTest.java
 
b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionBasicTest.java
index 4300c0a68c..c43e55027c 100644
--- 
a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionBasicTest.java
+++ 
b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionBasicTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.iotdb.db.metadata.schemaRegion;
 
+import org.apache.iotdb.common.rpc.thrift.TSchemaNode;
 import org.apache.iotdb.commons.exception.MetadataException;
 import org.apache.iotdb.commons.path.MeasurementPath;
 import org.apache.iotdb.commons.path.PartialPath;
@@ -25,11 +26,18 @@ import org.apache.iotdb.commons.path.PathPatternTree;
 import org.apache.iotdb.db.exception.metadata.AliasAlreadyExistException;
 import org.apache.iotdb.db.exception.metadata.MeasurementAlreadyExistException;
 import org.apache.iotdb.db.exception.metadata.PathAlreadyExistException;
+import org.apache.iotdb.db.metadata.mnode.MNodeType;
+import 
org.apache.iotdb.db.metadata.plan.schemaregion.impl.CreateAlignedTimeSeriesPlanImpl;
 import 
org.apache.iotdb.db.metadata.plan.schemaregion.impl.CreateTimeSeriesPlanImpl;
 import org.apache.iotdb.db.metadata.schemaregion.ISchemaRegion;
+import org.apache.iotdb.db.qp.physical.sys.ShowDevicesPlan;
+import org.apache.iotdb.db.qp.physical.sys.ShowTimeSeriesPlan;
+import org.apache.iotdb.db.query.dataset.ShowDevicesResult;
+import org.apache.iotdb.db.query.dataset.ShowTimeSeriesResult;
 import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+import org.apache.iotdb.tsfile.utils.Pair;
 
 import org.apache.commons.lang3.StringUtils;
 import org.junit.Assert;
@@ -39,6 +47,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -130,6 +139,27 @@ public class SchemaRegionBasicTest extends 
AbstractSchemaRegionTest {
         CompressionType.GZIP, 
schemas.get(0).getMeasurementSchema().getCompressor());
   }
 
+  @Test
+  public void testCreateAlignedTimeseries() throws Exception {
+    ISchemaRegion schemaRegion = getSchemaRegion("root.sg", 0);
+    schemaRegion.createAlignedTimeSeries(
+        new CreateAlignedTimeSeriesPlanImpl(
+            new PartialPath("root.sg.wf02.wt01"),
+            Arrays.asList("temperature", "status"),
+            Arrays.asList(TSDataType.valueOf("FLOAT"), 
TSDataType.valueOf("INT32")),
+            Arrays.asList(TSEncoding.valueOf("RLE"), 
TSEncoding.valueOf("RLE")),
+            Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY),
+            null,
+            null,
+            null));
+    Map<Integer, MetadataException> checkRes =
+        schemaRegion.checkMeasurementExistence(
+            new PartialPath("root.sg.wf02.wt01"), Arrays.asList("temperature", 
"status"), null);
+    Assert.assertEquals(2, checkRes.size());
+    Assert.assertTrue(checkRes.get(0) instanceof 
MeasurementAlreadyExistException);
+    Assert.assertTrue(checkRes.get(1) instanceof 
MeasurementAlreadyExistException);
+  }
+
   @Test
   public void testCheckMeasurementExistence() throws Exception {
     ISchemaRegion schemaRegion = getSchemaRegion("root.sg", 0);
@@ -284,4 +314,409 @@ public class SchemaRegionBasicTest extends 
AbstractSchemaRegionTest {
     Assert.assertEquals(1, schemas.size());
     Assert.assertEquals("root.sg.wf02.wt01.temperature", 
schemas.get(0).getFullPath());
   }
+
+  @Test
+  public void testGetAllTimeseriesCount() throws Exception {
+    ISchemaRegion schemaRegion = getSchemaRegion("root.laptop", 0);
+
+    SchemaRegionTestUtil.createSimpleTimeseriesByList(
+        schemaRegion,
+        Arrays.asList(
+            "root.laptop.d0",
+            "root.laptop.d1.s1",
+            "root.laptop.d1.s2.t1",
+            "root.laptop.d1.s3",
+            "root.laptop.d2.s1",
+            "root.laptop.d2.s2"));
+
+    // for Non prefix matched path
+    Assert.assertEquals(
+        6, schemaRegion.getAllTimeseriesCount(new PartialPath("root.**"), 
null, false));
+    Assert.assertEquals(
+        6, schemaRegion.getAllTimeseriesCount(new 
PartialPath("root.laptop.**"), null, false));
+    Assert.assertEquals(
+        1, schemaRegion.getAllTimeseriesCount(new 
PartialPath("root.laptop.*"), null, false));
+    Assert.assertEquals(
+        4, schemaRegion.getAllTimeseriesCount(new 
PartialPath("root.laptop.*.*"), null, false));
+    Assert.assertEquals(
+        5, schemaRegion.getAllTimeseriesCount(new 
PartialPath("root.laptop.*.**"), null, false));
+    Assert.assertEquals(
+        1, schemaRegion.getAllTimeseriesCount(new 
PartialPath("root.laptop.*.*.t1"), null, false));
+    Assert.assertEquals(
+        2, schemaRegion.getAllTimeseriesCount(new 
PartialPath("root.laptop.*.s1"), null, false));
+    Assert.assertEquals(
+        3, schemaRegion.getAllTimeseriesCount(new 
PartialPath("root.laptop.d1.**"), null, false));
+    Assert.assertEquals(
+        2, schemaRegion.getAllTimeseriesCount(new 
PartialPath("root.laptop.d1.*"), null, false));
+    Assert.assertEquals(
+        1, schemaRegion.getAllTimeseriesCount(new 
PartialPath("root.laptop.d2.s1"), null, false));
+    Assert.assertEquals(
+        2, schemaRegion.getAllTimeseriesCount(new 
PartialPath("root.laptop.d2.**"), null, false));
+    Assert.assertEquals(
+        0, schemaRegion.getAllTimeseriesCount(new PartialPath("root.laptop"), 
null, false));
+    Assert.assertEquals(
+        0, schemaRegion.getAllTimeseriesCount(new 
PartialPath("root.laptop.d3.s1"), null, false));
+
+    // for prefix matched path
+    Assert.assertEquals(6, schemaRegion.getAllTimeseriesCount(new 
PartialPath("root"), null, true));
+    Assert.assertEquals(
+        6, schemaRegion.getAllTimeseriesCount(new PartialPath("root.laptop"), 
null, true));
+    Assert.assertEquals(
+        2, schemaRegion.getAllTimeseriesCount(new 
PartialPath("root.laptop.d2"), null, true));
+  }
+
+  @Test
+  public void testGetMeasurementCountGroupByLevel() throws Exception {
+    ISchemaRegion schemaRegion = getSchemaRegion("root.laptop", 0);
+
+    SchemaRegionTestUtil.createSimpleTimeseriesByList(
+        schemaRegion,
+        Arrays.asList(
+            "root.laptop.d0",
+            "root.laptop.d1.s1",
+            "root.laptop.d1.s2.t1",
+            "root.laptop.d1.s3",
+            "root.laptop.d2.s1",
+            "root.laptop.d2.s2"));
+
+    Map<PartialPath, Long> expected = new HashMap<>();
+    expected.put(new PartialPath("root"), (long) 6);
+    Assert.assertEquals(
+        expected,
+        schemaRegion.getMeasurementCountGroupByLevel(new 
PartialPath("root.**"), 0, false));
+    expected.clear();
+
+    expected.put(new PartialPath("root.laptop"), (long) 1);
+    Assert.assertEquals(
+        expected,
+        schemaRegion.getMeasurementCountGroupByLevel(new 
PartialPath("root.laptop.*"), 1, false));
+    expected.clear();
+
+    expected.put(new PartialPath("root.laptop.d0"), (long) 1);
+    Assert.assertEquals(
+        expected,
+        schemaRegion.getMeasurementCountGroupByLevel(new 
PartialPath("root.laptop.d0"), 2, false));
+    expected.clear();
+
+    expected.put(new PartialPath("root.laptop.d1"), (long) 0);
+    Assert.assertEquals(
+        expected,
+        schemaRegion.getMeasurementCountGroupByLevel(new 
PartialPath("root.laptop.d1"), 2, false));
+    expected.clear();
+
+    expected.put(new PartialPath("root.laptop.d1"), (long) 2);
+    Assert.assertEquals(
+        expected,
+        schemaRegion.getMeasurementCountGroupByLevel(
+            new PartialPath("root.laptop.d1.*"), 2, false));
+    expected.clear();
+
+    expected.put(new PartialPath("root.laptop.d1"), (long) 3);
+    Assert.assertEquals(
+        expected,
+        schemaRegion.getMeasurementCountGroupByLevel(
+            new PartialPath("root.laptop.d1.**"), 2, false));
+    expected.clear();
+
+    expected.put(new PartialPath("root.laptop.d2"), (long) 2);
+    Assert.assertEquals(
+        expected,
+        schemaRegion.getMeasurementCountGroupByLevel(
+            new PartialPath("root.laptop.d2.*"), 2, false));
+    expected.clear();
+
+    expected.put(new PartialPath("root.laptop"), (long) 2);
+    Assert.assertEquals(
+        expected,
+        schemaRegion.getMeasurementCountGroupByLevel(
+            new PartialPath("root.laptop.*.s1"), 1, false));
+    expected.clear();
+
+    expected.put(new PartialPath("root.laptop.d0"), (long) 0);
+    expected.put(new PartialPath("root.laptop.d1"), (long) 1);
+    expected.put(new PartialPath("root.laptop.d2"), (long) 1);
+    Assert.assertEquals(
+        expected,
+        schemaRegion.getMeasurementCountGroupByLevel(
+            new PartialPath("root.laptop.*.s1"), 2, false));
+    expected.clear();
+
+    expected.put(new PartialPath("root.laptop"), (long) 1);
+    Assert.assertEquals(
+        expected,
+        schemaRegion.getMeasurementCountGroupByLevel(
+            new PartialPath("root.laptop.*.s2"), 1, false));
+    expected.clear();
+
+    expected.put(new PartialPath("root.laptop.d0"), (long) 0);
+    expected.put(new PartialPath("root.laptop.d1"), (long) 2);
+    expected.put(new PartialPath("root.laptop.d2"), (long) 2);
+    Assert.assertEquals(
+        expected,
+        schemaRegion.getMeasurementCountGroupByLevel(new 
PartialPath("root.laptop.*.*"), 2, false));
+    expected.clear();
+
+    // for prefix matched path
+    expected.put(new PartialPath("root"), (long) 6);
+    Assert.assertEquals(
+        expected, schemaRegion.getMeasurementCountGroupByLevel(new 
PartialPath("root"), 0, true));
+    expected.clear();
+
+    expected.put(new PartialPath("root.laptop.d1"), (long) 3);
+    Assert.assertEquals(
+        expected,
+        schemaRegion.getMeasurementCountGroupByLevel(new 
PartialPath("root.laptop.d1"), 2, true));
+    expected.clear();
+  }
+
+  @Test
+  public void testGetDevicesNum() throws Exception {
+    ISchemaRegion schemaRegion = getSchemaRegion("root.laptop", 0);
+
+    SchemaRegionTestUtil.createSimpleTimeseriesByList(
+        schemaRegion,
+        Arrays.asList(
+            "root.laptop.d0",
+            "root.laptop.d1.s1",
+            "root.laptop.d1.s2.t1",
+            "root.laptop.d1.s3",
+            "root.laptop.d2.s1",
+            "root.laptop.d2.s2"));
+
+    Assert.assertEquals(4, schemaRegion.getDevicesNum(new 
PartialPath("root.**"), false));
+    Assert.assertEquals(1, schemaRegion.getDevicesNum(new 
PartialPath("root.laptop"), false));
+    Assert.assertEquals(2, schemaRegion.getDevicesNum(new 
PartialPath("root.laptop.*"), false));
+    Assert.assertEquals(0, schemaRegion.getDevicesNum(new 
PartialPath("root.laptop.d0"), false));
+    Assert.assertEquals(1, schemaRegion.getDevicesNum(new 
PartialPath("root.laptop.d1"), false));
+    Assert.assertEquals(1, schemaRegion.getDevicesNum(new 
PartialPath("root.laptop.d1.s2"), false));
+    Assert.assertEquals(1, schemaRegion.getDevicesNum(new 
PartialPath("root.laptop.d2"), false));
+    Assert.assertEquals(2, schemaRegion.getDevicesNum(new 
PartialPath("root.laptop.d*"), false));
+    Assert.assertEquals(2, schemaRegion.getDevicesNum(new 
PartialPath("root.*.d*"), false));
+    Assert.assertEquals(1, schemaRegion.getDevicesNum(new 
PartialPath("root.**.s2"), false));
+
+    // for prefix matched path
+    Assert.assertEquals(4, schemaRegion.getDevicesNum(new PartialPath("root"), 
true));
+    Assert.assertEquals(4, schemaRegion.getDevicesNum(new 
PartialPath("root.laptop"), true));
+    Assert.assertEquals(3, schemaRegion.getDevicesNum(new 
PartialPath("root.laptop.d*"), true));
+    Assert.assertEquals(1, schemaRegion.getDevicesNum(new 
PartialPath("root.laptop.d1.*"), true));
+  }
+
+  @Test
+  public void testGetNodesListInGivenLevel() throws Exception {
+    ISchemaRegion schemaRegion = getSchemaRegion("root.laptop", 0);
+
+    SchemaRegionTestUtil.createSimpleTimeseriesByList(
+        schemaRegion,
+        Arrays.asList(
+            "root.laptop.d0",
+            "root.laptop.d1.s1",
+            "root.laptop.d1.s2.t1",
+            "root.laptop.d1.s3",
+            "root.laptop.d2.s1",
+            "root.laptop.d2.s2"));
+
+    Assert.assertEquals(
+        new LinkedList<>(Arrays.asList(new PartialPath("root"))),
+        schemaRegion.getNodesListInGivenLevel(new PartialPath("root.**"), 0, 
false));
+    Assert.assertEquals(
+        new LinkedList<>(Arrays.asList(new PartialPath("root.laptop"))),
+        schemaRegion.getNodesListInGivenLevel(new PartialPath("root.**"), 1, 
false));
+    Assert.assertEquals(
+        new LinkedList<>(Arrays.asList(new PartialPath("root.laptop"))),
+        schemaRegion.getNodesListInGivenLevel(new PartialPath("root.laptop"), 
1, false));
+    Assert.assertEquals(
+        new HashSet<>(
+            Arrays.asList(
+                new PartialPath("root.laptop.d0"),
+                new PartialPath("root.laptop.d1"),
+                new PartialPath("root.laptop.d2"))),
+        new HashSet<>(
+            schemaRegion.getNodesListInGivenLevel(new 
PartialPath("root.laptop.**"), 2, false)));
+    Assert.assertEquals(
+        new HashSet<>(
+            Arrays.asList(
+                new PartialPath("root.laptop.d1.s1"),
+                new PartialPath("root.laptop.d1.s2"),
+                new PartialPath("root.laptop.d1.s3"),
+                new PartialPath("root.laptop.d2.s1"),
+                new PartialPath("root.laptop.d2.s2"))),
+        new HashSet<>(
+            schemaRegion.getNodesListInGivenLevel(new 
PartialPath("root.laptop.**"), 3, false)));
+    Assert.assertEquals(
+        new HashSet<>(
+            Arrays.asList(
+                new PartialPath("root.laptop.d1.s1"), new 
PartialPath("root.laptop.d2.s1"))),
+        new HashSet<>(
+            schemaRegion.getNodesListInGivenLevel(new 
PartialPath("root.laptop.*.s1"), 3, false)));
+    // Empty return
+    Assert.assertEquals(
+        new HashSet<>(Arrays.asList()),
+        new HashSet<>(
+            schemaRegion.getNodesListInGivenLevel(
+                new PartialPath("root.laptop.notExists"), 1, false)));
+  }
+
+  @Test
+  public void testGetChildNodePathInNextLevel() throws Exception {
+    ISchemaRegion schemaRegion = getSchemaRegion("root.laptop", 0);
+
+    SchemaRegionTestUtil.createSimpleTimeseriesByList(
+        schemaRegion,
+        Arrays.asList(
+            "root.laptop.d0",
+            "root.laptop.d1.s1",
+            "root.laptop.d1.s2.t1",
+            "root.laptop.d1.s3",
+            "root.laptop.d2.s1",
+            "root.laptop.d2.s2"));
+
+    Assert.assertEquals(
+        new HashSet<>(Arrays.asList()),
+        schemaRegion.getChildNodePathInNextLevel(new 
PartialPath("root.laptop.d0")));
+
+    Assert.assertEquals(
+        new HashSet<>(
+            Arrays.asList(
+                new TSchemaNode("root.laptop.d1.s1", 
MNodeType.MEASUREMENT.getNodeType()),
+                new TSchemaNode("root.laptop.d1.s2", 
MNodeType.DEVICE.getNodeType()),
+                new TSchemaNode("root.laptop.d1.s3", 
MNodeType.MEASUREMENT.getNodeType()))),
+        schemaRegion.getChildNodePathInNextLevel(new 
PartialPath("root.laptop.d1")));
+
+    Assert.assertEquals(
+        new HashSet<>(
+            Arrays.asList(
+                new TSchemaNode("root.laptop.d2.s1", 
MNodeType.MEASUREMENT.getNodeType()),
+                new TSchemaNode("root.laptop.d2.s2", 
MNodeType.MEASUREMENT.getNodeType()))),
+        schemaRegion.getChildNodePathInNextLevel(new 
PartialPath("root.laptop.d2")));
+
+    Assert.assertEquals(
+        new HashSet<>(
+            Arrays.asList(
+                new TSchemaNode("root.laptop.d0", 
MNodeType.MEASUREMENT.getNodeType()),
+                new TSchemaNode("root.laptop.d1", 
MNodeType.DEVICE.getNodeType()),
+                new TSchemaNode("root.laptop.d2", 
MNodeType.DEVICE.getNodeType()))),
+        schemaRegion.getChildNodePathInNextLevel(new 
PartialPath("root.laptop")));
+
+    Assert.assertEquals(
+        new HashSet<>(
+            Arrays.asList(
+                new TSchemaNode("root.laptop.d1.s2.t1", 
MNodeType.MEASUREMENT.getNodeType()))),
+        schemaRegion.getChildNodePathInNextLevel(new 
PartialPath("root.**.s2")));
+  }
+
+  @Test
+  public void testGetMatchedDevices() throws Exception {
+    ISchemaRegion schemaRegion = getSchemaRegion("root.laptop", 0);
+
+    SchemaRegionTestUtil.createSimpleTimeseriesByList(
+        schemaRegion,
+        Arrays.asList(
+            "root.laptop.d0",
+            "root.laptop.d1.s1",
+            "root.laptop.d1.s2.t1",
+            "root.laptop.d1.s3",
+            "root.laptop.d2.s1",
+            "root.laptop.d2.s2"));
+
+    Assert.assertEquals(
+        new Pair<>(Arrays.asList(), 0),
+        schemaRegion.getMatchedDevices(new ShowDevicesPlan(new 
PartialPath("root.laptop.d0"))));
+    Assert.assertEquals(
+        new Pair<>(Arrays.asList(new ShowDevicesResult("root.laptop.d1", 
false)), 0),
+        schemaRegion.getMatchedDevices(new ShowDevicesPlan(new 
PartialPath("root.laptop.d1"))));
+    Assert.assertEquals(
+        new Pair<>(Arrays.asList(new ShowDevicesResult("root.laptop.d2", 
false)), 0),
+        schemaRegion.getMatchedDevices(new ShowDevicesPlan(new 
PartialPath("root.laptop.d2"))));
+    Assert.assertEquals(
+        new Pair<>(Arrays.asList(new ShowDevicesResult("root.laptop", false)), 
0),
+        schemaRegion.getMatchedDevices(new ShowDevicesPlan(new 
PartialPath("root.laptop"))));
+    Assert.assertEquals(
+        new Pair<>(Arrays.asList(new ShowDevicesResult("root.laptop", false)), 
0),
+        schemaRegion.getMatchedDevices(new ShowDevicesPlan(new 
PartialPath("root.*"))));
+
+    List<ShowDevicesResult> expectedList =
+        Arrays.asList(
+            new ShowDevicesResult("root.laptop", false),
+            new ShowDevicesResult("root.laptop.d1", false),
+            new ShowDevicesResult("root.laptop.d2", false),
+            new ShowDevicesResult("root.laptop.d1.s2", false));
+    Integer expectedOffset = 0;
+    Pair<List<ShowDevicesResult>, Integer> actualResult =
+        schemaRegion.getMatchedDevices(new ShowDevicesPlan(new 
PartialPath("root.**")));
+    // Compare hash sets because the order does not matter.
+    HashSet<ShowDevicesResult> expectedHashset = new HashSet<>(expectedList);
+    HashSet<ShowDevicesResult> actualHashset = new 
HashSet<>(actualResult.left);
+    Assert.assertEquals(expectedHashset, actualHashset);
+    Assert.assertEquals(expectedOffset, actualResult.right);
+
+    expectedList =
+        Arrays.asList(
+            new ShowDevicesResult("root.laptop.d1", false),
+            new ShowDevicesResult("root.laptop.d2", false));
+    expectedOffset = 0;
+    actualResult =
+        schemaRegion.getMatchedDevices(new ShowDevicesPlan(new 
PartialPath("root.**.d*")));
+    // Compare hash sets because the order does not matter.
+    expectedHashset = new HashSet<>(expectedList);
+    actualHashset = new HashSet<>(actualResult.left);
+    Assert.assertEquals(expectedHashset, actualHashset);
+    Assert.assertEquals(expectedOffset, actualResult.right);
+  }
+
+  @Test
+  public void testShowTimeseries() throws Exception {
+    ISchemaRegion schemaRegion = getSchemaRegion("root.laptop", 0);
+
+    SchemaRegionTestUtil.createSimpleTimeseriesByList(
+        schemaRegion,
+        Arrays.asList(
+            "root.laptop.d0",
+            "root.laptop.d1.s1",
+            "root.laptop.d1.s2.t1",
+            "root.laptop.d1.s3",
+            "root.laptop.d2.s1",
+            "root.laptop.d2.s2"));
+
+    // case 01: all timeseries
+    Pair<List<ShowTimeSeriesResult>, Integer> result =
+        schemaRegion.showTimeseries(
+            new ShowTimeSeriesPlan(new PartialPath("root.**"), false, null, 
null, 0, 0, false),
+            null);
+    HashSet<String> expectedPathList =
+        new HashSet<>(
+            Arrays.asList(
+                "root.laptop.d0",
+                "root.laptop.d1.s1",
+                "root.laptop.d1.s2.t1",
+                "root.laptop.d1.s3",
+                "root.laptop.d2.s1",
+                "root.laptop.d2.s2"));
+    int expectedSize = 6;
+    Assert.assertEquals(expectedSize, result.left.size());
+    HashSet<String> actualPathList = new HashSet<>();
+    for (int index = 0; index < expectedSize; index++) {
+      actualPathList.add(result.left.get(index).getName());
+    }
+    Assert.assertEquals(expectedPathList, actualPathList);
+
+    // case 02: some timeseries, pattern "root.**.s*"
+    result =
+        schemaRegion.showTimeseries(
+            new ShowTimeSeriesPlan(new PartialPath("root.**.s*"), false, null, 
null, 0, 0, false),
+            null);
+    expectedPathList =
+        new HashSet<>(
+            Arrays.asList(
+                "root.laptop.d1.s1",
+                "root.laptop.d1.s3",
+                "root.laptop.d2.s1",
+                "root.laptop.d2.s2"));
+    expectedSize = 4;
+    Assert.assertEquals(expectedSize, result.left.size());
+    actualPathList = new HashSet<>();
+    for (int index = 0; index < expectedSize; index++) {
+      actualPathList.add(result.left.get(index).getName());
+    }
+    Assert.assertEquals(expectedPathList, actualPathList);
+  }
 }
diff --git 
a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionTestUtil.java
 
b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionTestUtil.java
index 51c2c3deea..89f60fda24 100644
--- 
a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionTestUtil.java
+++ 
b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionTestUtil.java
@@ -104,4 +104,37 @@ public class SchemaRegionTestUtil {
             tags,
             attributes));
   }
+
+  /**
+   * When testing some interfaces, if you only care about path and do not care 
the data type or
+   * compression type and other details, then use this function to create a 
timeseries quickly. It
+   * returns a CreateTimeSeriesPlanImpl with data type of INT64, TSEncoding of 
PLAIN, compression
+   * type of SNAPPY and without any tags or templates.
+   */
+  public static void createSimpleTimeSeriesInt64(ISchemaRegion schemaRegion, 
String path)
+      throws Exception {
+    SchemaRegionTestUtil.createTimeseries(
+        schemaRegion,
+        path,
+        TSDataType.INT64,
+        TSEncoding.PLAIN,
+        CompressionType.SNAPPY,
+        null,
+        null,
+        null,
+        null);
+  }
+
+  /**
+   * Create timeseries quickly using createSimpleTimeSeriesInt64 with given 
string list of paths.
+   *
+   * @param schemaRegion schemaRegion which you want to create timeseries
+   * @param pathList
+   */
+  public static void createSimpleTimeseriesByList(ISchemaRegion schemaRegion, 
List<String> pathList)
+      throws Exception {
+    for (String path : pathList) {
+      SchemaRegionTestUtil.createSimpleTimeSeriesInt64(schemaRegion, path);
+    }
+  }
 }

Reply via email to