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

[iotdb] branch master updated: [IOTDB-5238] UT related to alias and tags and attributes (#8520)

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 f929e255e4 [IOTDB-5238] UT related to alias and tags and attributes (#8520)
f929e255e4 is described below

commit f929e255e4956fa3d74d9b53c574e7a049b2ebe6
Author: Chen YZ <43...@users.noreply.github.com>
AuthorDate: Tue Dec 20 14:02:11 2022 +0800

    [IOTDB-5238] UT related to alias and tags and attributes (#8520)
    
    [IOTDB-5238] UT related to alias and tags and attributes (#8520)
---
 .../schemaregion/rocksdb/RSchemaRegion.java        |   4 +-
 .../metadata/tagSchemaRegion/TagSchemaRegion.java  |   2 +-
 .../iotdb/db/metadata/LocalSchemaProcessor.java    |   2 +-
 .../db/metadata/schemaregion/ISchemaRegion.java    |  26 +-
 .../schemaregion/SchemaRegionMemoryImpl.java       |  20 +-
 .../schemaregion/SchemaRegionSchemaFileImpl.java   |  20 +-
 .../apache/iotdb/db/metadata/tag/TagManager.java   |  10 +-
 .../metadata/visitor/SchemaExecutionVisitor.java   |   2 +-
 .../schemaRegion/SchemaRegionAliasAndTagTest.java  | 480 ++++++++++++++++++++-
 .../schemaRegion/SchemaRegionTestUtil.java         | 107 +++++
 10 files changed, 642 insertions(+), 31 deletions(-)

diff --git a/schema-engine-rocksdb/src/main/java/org/apache/iotdb/db/metadata/schemaregion/rocksdb/RSchemaRegion.java b/schema-engine-rocksdb/src/main/java/org/apache/iotdb/db/metadata/schemaregion/rocksdb/RSchemaRegion.java
index 6ccb350635..dd6626dc48 100644
--- a/schema-engine-rocksdb/src/main/java/org/apache/iotdb/db/metadata/schemaregion/rocksdb/RSchemaRegion.java
+++ b/schema-engine-rocksdb/src/main/java/org/apache/iotdb/db/metadata/schemaregion/rocksdb/RSchemaRegion.java
@@ -1308,11 +1308,11 @@ public class RSchemaRegion implements ISchemaRegion {
 
   @Override
   public void changeAlias(PartialPath path, String alias) throws MetadataException, IOException {
-    upsertTagsAndAttributes(alias, null, null, path);
+    upsertAliasAndTagsAndAttributes(alias, null, null, path);
   }
 
   @Override
-  public void upsertTagsAndAttributes(
+  public void upsertAliasAndTagsAndAttributes(
       String alias,
       Map<String, String> tagsMap,
       Map<String, String> attributesMap,
diff --git a/schema-engine-tag/src/main/java/org/apache/iotdb/db/metadata/tagSchemaRegion/TagSchemaRegion.java b/schema-engine-tag/src/main/java/org/apache/iotdb/db/metadata/tagSchemaRegion/TagSchemaRegion.java
index 637ad588de..a2d0d24d50 100644
--- a/schema-engine-tag/src/main/java/org/apache/iotdb/db/metadata/tagSchemaRegion/TagSchemaRegion.java
+++ b/schema-engine-tag/src/main/java/org/apache/iotdb/db/metadata/tagSchemaRegion/TagSchemaRegion.java
@@ -673,7 +673,7 @@ public class TagSchemaRegion implements ISchemaRegion {
   }
 
   @Override
-  public void upsertTagsAndAttributes(
+  public void upsertAliasAndTagsAndAttributes(
       String alias,
       Map<String, String> tagsMap,
       Map<String, String> attributesMap,
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/LocalSchemaProcessor.java b/server/src/main/java/org/apache/iotdb/db/metadata/LocalSchemaProcessor.java
index 2856370eeb..29cd22f951 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/LocalSchemaProcessor.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/LocalSchemaProcessor.java
@@ -808,7 +808,7 @@ public class LocalSchemaProcessor {
       PartialPath fullPath)
       throws MetadataException, IOException {
     getBelongedSchemaRegion(fullPath)
-        .upsertTagsAndAttributes(alias, tagsMap, attributesMap, fullPath);
+        .upsertAliasAndTagsAndAttributes(alias, tagsMap, attributesMap, fullPath);
   }
 
   /**
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 be5c425cc7..610021ef21 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
@@ -161,6 +161,7 @@ public interface ISchemaRegion {
    *
    * @param path a full path or a prefix path
    */
+  @Deprecated
   boolean isPathExist(PartialPath path) throws MetadataException;
 
   // region Interfaces for metadata count
@@ -254,7 +255,7 @@ public interface ISchemaRegion {
       throws MetadataException;
 
   /**
-   * Get all device paths and according database paths as ShowDevicesResult.
+   * Get all device paths and corresponding database paths as ShowDevicesResult.
    *
    * @param plan ShowDevicesPlan which contains the path pattern and restriction params.
    * @return ShowDevicesResult and the current offset of this region after traverse.
@@ -304,18 +305,19 @@ public interface ISchemaRegion {
   // endregion
 
   // region Interfaces for alias and tag/attribute operations
+  @Deprecated
   void changeAlias(PartialPath path, String alias) throws MetadataException, IOException;
 
   /**
-   * upsert tags and attributes key-value for the timeseries if the key has existed, just use the
-   * new value to update it.
+   * Upsert alias, tags and attributes key-value for the timeseries if the key has existed, just use
+   * the new value to update it.
    *
    * @param alias newly added alias
    * @param tagsMap newly added tags map
    * @param attributesMap newly added attributes map
    * @param fullPath timeseries
    */
-  void upsertTagsAndAttributes(
+  void upsertAliasAndTagsAndAttributes(
       String alias,
       Map<String, String> tagsMap,
       Map<String, String> attributesMap,
@@ -323,25 +325,28 @@ public interface ISchemaRegion {
       throws MetadataException, IOException;
 
   /**
-   * add new attributes key-value for the timeseries
+   * Add new attributes key-value for the timeseries
    *
    * @param attributesMap newly added attributes map
    * @param fullPath timeseries
+   * @throws MetadataException tagLogFile write error or attributes already exist
    */
   void addAttributes(Map<String, String> attributesMap, PartialPath fullPath)
       throws MetadataException, IOException;
 
   /**
-   * add new tags key-value for the timeseries
+   * Add new tags key-value for the timeseries
    *
    * @param tagsMap newly added tags map
    * @param fullPath timeseries
+   * @throws MetadataException tagLogFile write error or tags already exist
    */
   void addTags(Map<String, String> tagsMap, PartialPath fullPath)
       throws MetadataException, IOException;
 
   /**
-   * drop tags or attributes of the timeseries
+   * Drop tags or attributes of the timeseries. It will not throw exception even if the key does not
+   * exist.
    *
    * @param keySet tags key or attributes key
    * @param fullPath timeseries path
@@ -350,20 +355,23 @@ public interface ISchemaRegion {
       throws MetadataException, IOException;
 
   /**
-   * set/change the values of tags or attributes
+   * Set/change the values of tags or attributes
    *
    * @param alterMap the new tags or attributes key-value
    * @param fullPath timeseries
+   * @throws MetadataException tagLogFile write error or tags/attributes do not exist
    */
   void setTagsOrAttributesValue(Map<String, String> alterMap, PartialPath fullPath)
       throws MetadataException, IOException;
 
   /**
-   * rename the tag or attribute's key of the timeseries
+   * Rename the tag or attribute's key of the timeseries
    *
    * @param oldKey old key of tag or attribute
    * @param newKey new key of tag or attribute
    * @param fullPath timeseries
+   * @throws MetadataException tagLogFile write error or does not have tag/attribute or already has
+   *     a tag/attribute named newKey
    */
   void renameTagOrAttributeKey(String oldKey, String newKey, PartialPath fullPath)
       throws MetadataException, IOException;
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionMemoryImpl.java b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionMemoryImpl.java
index 1665a2854a..49705f157e 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionMemoryImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionMemoryImpl.java
@@ -1361,7 +1361,7 @@ public class SchemaRegionMemoryImpl implements ISchemaRegion {
   }
 
   /**
-   * upsert tags and attributes key-value for the timeseries if the key has existed, just use the
+   * Upsert tags and attributes key-value for the timeseries if the key has existed, just use the
    * new value to update it.
    *
    * @param alias newly added alias
@@ -1371,7 +1371,7 @@ public class SchemaRegionMemoryImpl implements ISchemaRegion {
    */
   @Override
   @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
-  public void upsertTagsAndAttributes(
+  public void upsertAliasAndTagsAndAttributes(
       String alias,
       Map<String, String> tagsMap,
       Map<String, String> attributesMap,
@@ -1420,10 +1420,11 @@ public class SchemaRegionMemoryImpl implements ISchemaRegion {
   }
 
   /**
-   * add new attributes key-value for the timeseries
+   * Add new attributes key-value for the timeseries
    *
    * @param attributesMap newly added attributes map
    * @param fullPath timeseries
+   * @throws MetadataException tagLogFile write error or attributes already exist
    */
   @Override
   public void addAttributes(Map<String, String> attributesMap, PartialPath fullPath)
@@ -1442,10 +1443,11 @@ public class SchemaRegionMemoryImpl implements ISchemaRegion {
   }
 
   /**
-   * add new tags key-value for the timeseries
+   * Add new tags key-value for the timeseries
    *
    * @param tagsMap newly added tags map
    * @param fullPath timeseries
+   * @throws MetadataException tagLogFile write error or tags already exist
    */
   @Override
   public void addTags(Map<String, String> tagsMap, PartialPath fullPath)
@@ -1465,7 +1467,8 @@ public class SchemaRegionMemoryImpl implements ISchemaRegion {
   }
 
   /**
-   * drop tags or attributes of the timeseries
+   * Drop tags or attributes of the timeseries. It will not throw exception even if the key does not
+   * exist.
    *
    * @param keySet tags key or attributes key
    * @param fullPath timeseries path
@@ -1482,10 +1485,11 @@ public class SchemaRegionMemoryImpl implements ISchemaRegion {
   }
 
   /**
-   * set/change the values of tags or attributes
+   * Set/change the values of tags or attributes
    *
    * @param alterMap the new tags or attributes key-value
    * @param fullPath timeseries
+   * @throws MetadataException tagLogFile write error or tags/attributes do not exist
    */
   @Override
   @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
@@ -1502,11 +1506,13 @@ public class SchemaRegionMemoryImpl implements ISchemaRegion {
   }
 
   /**
-   * rename the tag or attribute's key of the timeseries
+   * Rename the tag or attribute's key of the timeseries
    *
    * @param oldKey old key of tag or attribute
    * @param newKey new key of tag or attribute
    * @param fullPath timeseries
+   * @throws MetadataException tagLogFile write error or does not have tag/attribute or already has
+   *     a tag/attribute named newKey
    */
   @Override
   @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionSchemaFileImpl.java b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionSchemaFileImpl.java
index 1ddca04302..994017bae8 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionSchemaFileImpl.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionSchemaFileImpl.java
@@ -1458,7 +1458,7 @@ public class SchemaRegionSchemaFileImpl implements ISchemaRegion {
   }
 
   /**
-   * upsert tags and attributes key-value for the timeseries if the key has existed, just use the
+   * Upsert tags and attributes key-value for the timeseries if the key has existed, just use the
    * new value to update it.
    *
    * @param alias newly added alias
@@ -1468,7 +1468,7 @@ public class SchemaRegionSchemaFileImpl implements ISchemaRegion {
    */
   @Override
   @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
-  public void upsertTagsAndAttributes(
+  public void upsertAliasAndTagsAndAttributes(
       String alias,
       Map<String, String> tagsMap,
       Map<String, String> attributesMap,
@@ -1522,10 +1522,11 @@ public class SchemaRegionSchemaFileImpl implements ISchemaRegion {
   }
 
   /**
-   * add new attributes key-value for the timeseries
+   * Add new attributes key-value for the timeseries
    *
    * @param attributesMap newly added attributes map
    * @param fullPath timeseries
+   * @throws MetadataException tagLogFile write error or attributes already exist
    */
   @Override
   public void addAttributes(Map<String, String> attributesMap, PartialPath fullPath)
@@ -1548,10 +1549,11 @@ public class SchemaRegionSchemaFileImpl implements ISchemaRegion {
   }
 
   /**
-   * add new tags key-value for the timeseries
+   * Add new tags key-value for the timeseries
    *
    * @param tagsMap newly added tags map
    * @param fullPath timeseries
+   * @throws MetadataException tagLogFile write error or tags already exist
    */
   @Override
   public void addTags(Map<String, String> tagsMap, PartialPath fullPath)
@@ -1577,7 +1579,8 @@ public class SchemaRegionSchemaFileImpl implements ISchemaRegion {
   }
 
   /**
-   * drop tags or attributes of the timeseries
+   * Drop tags or attributes of the timeseries. It will not throw exception even if the key does not
+   * exist.
    *
    * @param keySet tags key or attributes key
    * @param fullPath timeseries path
@@ -1600,10 +1603,11 @@ public class SchemaRegionSchemaFileImpl implements ISchemaRegion {
   }
 
   /**
-   * set/change the values of tags or attributes
+   * Set/change the values of tags or attributes
    *
    * @param alterMap the new tags or attributes key-value
    * @param fullPath timeseries
+   * @throws MetadataException tagLogFile write error or tags/attributes do not exist
    */
   @Override
   @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
@@ -1624,11 +1628,13 @@ public class SchemaRegionSchemaFileImpl implements ISchemaRegion {
   }
 
   /**
-   * rename the tag or attribute's key of the timeseries
+   * Rename the tag or attribute's key of the timeseries
    *
    * @param oldKey old key of tag or attribute
    * @param newKey new key of tag or attribute
    * @param fullPath timeseries
+   * @throws MetadataException tagLogFile write error or does not have tag/attribute or already has
+   *     a tag/attribute named newKey
    */
   @Override
   @SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/tag/TagManager.java b/server/src/main/java/org/apache/iotdb/db/metadata/tag/TagManager.java
index 8c4a26e60e..66a025a374 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/tag/TagManager.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/tag/TagManager.java
@@ -342,6 +342,7 @@ public class TagManager {
    * add new attributes key-value for the timeseries
    *
    * @param attributesMap newly added attributes map
+   * @throws MetadataException tagLogFile write error or attributes already exist
    */
   public void addAttributes(
       Map<String, String> attributesMap, PartialPath fullPath, IMeasurementMNode leafMNode)
@@ -369,6 +370,7 @@ public class TagManager {
    *
    * @param tagsMap newly added tags map
    * @param fullPath timeseries
+   * @throws MetadataException tagLogFile write error or tag already exists
    */
   public void addTags(
       Map<String, String> tagsMap, PartialPath fullPath, IMeasurementMNode leafMNode)
@@ -395,7 +397,8 @@ public class TagManager {
   }
 
   /**
-   * drop tags or attributes of the timeseries
+   * Drop tags or attributes of the timeseries. It will not throw exception even if the key does not
+   * exist.
    *
    * @param keySet tags key or attributes key
    */
@@ -468,6 +471,7 @@ public class TagManager {
    * set/change the values of tags or attributes
    *
    * @param alterMap the new tags or attributes key-value
+   * @throws MetadataException tagLogFile write error or tags/attributes do not exist
    */
   public void setTagsOrAttributesValue(
       Map<String, String> alterMap, PartialPath fullPath, IMeasurementMNode leafMNode)
@@ -532,10 +536,12 @@ public class TagManager {
   }
 
   /**
-   * rename the tag or attribute's key of the timeseries
+   * Rename the tag or attribute's key of the timeseries
    *
    * @param oldKey old key of tag or attribute
    * @param newKey new key of tag or attribute
+   * @throws MetadataException tagLogFile write error or does not have tag/attribute or already has
+   *     a tag/attribute named newKey
    */
   public void renameTagOrAttributeKey(
       String oldKey, String newKey, PartialPath fullPath, IMeasurementMNode leafMNode)
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/visitor/SchemaExecutionVisitor.java b/server/src/main/java/org/apache/iotdb/db/metadata/visitor/SchemaExecutionVisitor.java
index 075e48db48..56b086c32f 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/visitor/SchemaExecutionVisitor.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/visitor/SchemaExecutionVisitor.java
@@ -262,7 +262,7 @@ public class SchemaExecutionVisitor extends PlanVisitor<TSStatus, ISchemaRegion>
           schemaRegion.addAttributes(node.getAlterMap(), node.getPath());
           break;
         case UPSERT:
-          schemaRegion.upsertTagsAndAttributes(
+          schemaRegion.upsertAliasAndTagsAndAttributes(
               node.getAlias(), node.getTagsMap(), node.getAttributesMap(), node.getPath());
           break;
       }
diff --git a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionAliasAndTagTest.java b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionAliasAndTagTest.java
index fbd6ba4bbc..6cdb78a1bf 100644
--- a/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionAliasAndTagTest.java
+++ b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionAliasAndTagTest.java
@@ -19,15 +19,493 @@
 
 package org.apache.iotdb.db.metadata.schemaRegion;
 
+import org.apache.iotdb.commons.exception.MetadataException;
+import org.apache.iotdb.commons.path.PartialPath;
+import org.apache.iotdb.db.metadata.schemaregion.ISchemaRegion;
+import org.apache.iotdb.db.qp.physical.sys.ShowTimeSeriesPlan;
+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.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 // todo add alias and tag test
 public class SchemaRegionAliasAndTagTest extends AbstractSchemaRegionTest {
 
+  private static final Logger logger = LoggerFactory.getLogger(SchemaRegionAliasAndTagTest.class);
+  private ISchemaRegion schemaRegion;
+
   public SchemaRegionAliasAndTagTest(SchemaRegionTestParams testParams) {
     super(testParams);
   }
 
+  @Before
+  public void setUp() throws Exception {
+    super.setUp();
+    schemaRegion = getSchemaRegion("root.sg", 0);
+  }
+  /**
+   * Prepare timeseries
+   *
+   * <p>"root.sg.wf01.wt01.v1.s1" without tags, attributes and alias
+   *
+   * <p>"root.sg.wf01.wt01.v1.s2" with tags, attributes and alias
+   *
+   * <p>"root.sg.wf01.aligned_device1.(s1,s2)" aligned without tags, attributes and alias
+   *
+   * <p>"root.sg.wf01.aligned_device2.(s1,s2)" aligned with tags, attributes and alias
+   */
+  private void prepareTimeseries() throws MetadataException {
+    SchemaRegionTestUtil.createTimeseries(
+        schemaRegion,
+        "root.sg.wf01.wt01.v1.s1",
+        TSDataType.BOOLEAN,
+        TSEncoding.PLAIN,
+        CompressionType.SNAPPY,
+        null,
+        null,
+        null,
+        null);
+    SchemaRegionTestUtil.createTimeseries(
+        schemaRegion,
+        "root.sg.wf01.wt01.v1.s2",
+        TSDataType.FLOAT,
+        TSEncoding.RLE,
+        CompressionType.GZIP,
+        null,
+        new HashMap<String, String>() {
+          {
+            put("tag1", "t1");
+            put("tag2", "t2");
+          }
+        },
+        new HashMap<String, String>() {
+          {
+            put("attr1", "a1");
+            put("attr2", "a2");
+          }
+        },
+        "temp");
+    SchemaRegionTestUtil.createAlignedTimeseries(
+        schemaRegion,
+        "root.sg.wf01.aligned_device1",
+        Arrays.asList("s1", "s2"),
+        Arrays.asList(TSDataType.INT64, TSDataType.INT32),
+        Arrays.asList(TSEncoding.PLAIN, TSEncoding.RLE),
+        Arrays.asList(CompressionType.SNAPPY, CompressionType.LZ4),
+        null,
+        null,
+        null);
+    SchemaRegionTestUtil.createAlignedTimeseries(
+        schemaRegion,
+        "root.sg.wf01.aligned_device2",
+        Arrays.asList("s1", "s2"),
+        Arrays.asList(TSDataType.INT64, TSDataType.INT32),
+        Arrays.asList(TSEncoding.PLAIN, TSEncoding.RLE),
+        Arrays.asList(CompressionType.SNAPPY, CompressionType.LZ4),
+        Arrays.asList(
+            new HashMap<String, String>() {
+              {
+                put("tag1", "t1");
+              }
+            },
+            new HashMap<String, String>() {
+              {
+                put("tag2", "t2");
+              }
+            }),
+        Arrays.asList(
+            new HashMap<String, String>() {
+              {
+                put("attr1", "a1");
+              }
+            },
+            new HashMap<String, String>() {
+              {
+                put("attr2", "a2");
+              }
+            }),
+        Arrays.asList("alias1", "alias2"));
+  }
+
+  private void checkAliasAndTagsAndAttributes(
+      String fullPath, String alias, Map<String, String> tags, Map<String, String> attributes) {
+    try {
+      Pair<List<ShowTimeSeriesResult>, Integer> result =
+          schemaRegion.showTimeseries(
+              new ShowTimeSeriesPlan(new PartialPath(fullPath), false, null, null, 0, 0, false),
+              null);
+      Assert.assertEquals(1, result.left.size());
+      Assert.assertEquals(fullPath, result.left.get(0).getName());
+      Assert.assertEquals(alias, result.left.get(0).getAlias());
+      Assert.assertEquals(tags, result.left.get(0).getTag());
+      Assert.assertEquals(attributes, result.left.get(0).getAttribute());
+    } catch (Exception e) {
+      logger.error(e.getMessage(), e);
+      Assert.fail(e.getMessage());
+    }
+  }
+
+  private void checkAttributes(String fullPath, Map<String, String> attributes) {
+    try {
+      Pair<List<ShowTimeSeriesResult>, Integer> result =
+          schemaRegion.showTimeseries(
+              new ShowTimeSeriesPlan(new PartialPath(fullPath), false, null, null, 0, 0, false),
+              null);
+      Assert.assertEquals(1, result.left.size());
+      Assert.assertEquals(fullPath, result.left.get(0).getName());
+      Assert.assertEquals(attributes, result.left.get(0).getAttribute());
+    } catch (Exception e) {
+      e.printStackTrace();
+      Assert.fail(e.getMessage());
+    }
+  }
+
+  private void checkTags(String fullPath, Map<String, String> tags) {
+    try {
+      Pair<List<ShowTimeSeriesResult>, Integer> result =
+          schemaRegion.showTimeseries(
+              new ShowTimeSeriesPlan(new PartialPath(fullPath), false, null, null, 0, 0, false),
+              null);
+      Assert.assertEquals(1, result.left.size());
+      Assert.assertEquals(fullPath, result.left.get(0).getName());
+      Assert.assertEquals(tags, result.left.get(0).getTag());
+    } catch (Exception e) {
+      logger.error(e.getMessage(), e);
+      Assert.fail(e.getMessage());
+    }
+  }
+
   @Test
-  public void emptyTest() {}
+  public void testShowTimeseries() throws MetadataException {
+    prepareTimeseries();
+    checkAliasAndTagsAndAttributes(
+        "root.sg.wf01.wt01.v1.s1", null, Collections.emptyMap(), Collections.emptyMap());
+    checkAliasAndTagsAndAttributes(
+        "root.sg.wf01.wt01.v1.s2",
+        "temp",
+        new HashMap<String, String>() {
+          {
+            put("tag1", "t1");
+            put("tag2", "t2");
+          }
+        },
+        new HashMap<String, String>() {
+          {
+            put("attr1", "a1");
+            put("attr2", "a2");
+          }
+        });
+    checkAliasAndTagsAndAttributes(
+        "root.sg.wf01.aligned_device1.s1", null, Collections.emptyMap(), Collections.emptyMap());
+    checkAliasAndTagsAndAttributes(
+        "root.sg.wf01.aligned_device1.s2", null, Collections.emptyMap(), Collections.emptyMap());
+    checkAliasAndTagsAndAttributes(
+        "root.sg.wf01.aligned_device2.s1",
+        "alias1",
+        new HashMap<String, String>() {
+          {
+            put("tag1", "t1");
+          }
+        },
+        new HashMap<String, String>() {
+          {
+            put("attr1", "a1");
+          }
+        });
+    checkAliasAndTagsAndAttributes(
+        "root.sg.wf01.aligned_device2.s2",
+        "alias2",
+        new HashMap<String, String>() {
+          {
+            put("tag2", "t2");
+          }
+        },
+        new HashMap<String, String>() {
+          {
+            put("attr2", "a2");
+          }
+        });
+  }
+
+  @Test
+  public void testUpsertAliasAndTagsAndAttributes() {
+    try {
+      prepareTimeseries();
+      Map<String, String> newTags =
+          new HashMap<String, String>() {
+            {
+              put("tag1", "new1");
+              put("tag2", "new2");
+              put("tag3", "new3");
+            }
+          };
+      Map<String, String> newAttributes =
+          new HashMap<String, String>() {
+            {
+              put("attr1", "new1");
+              put("attr2", "new2");
+              put("attr3", "new3");
+            }
+          };
+      List<String> fullPaths =
+          Arrays.asList(
+              "root.sg.wf01.wt01.v1.s1",
+              "root.sg.wf01.wt01.v1.s2",
+              "root.sg.wf01.aligned_device1.s1",
+              "root.sg.wf01.aligned_device1.s2",
+              "root.sg.wf01.aligned_device2.s1",
+              "root.sg.wf01.aligned_device2.s2");
+      List<String> aliasList =
+          Arrays.asList(
+              "newAlias1", "newAlias2", "newAlias3", "newAlias4", "newAlias5", "newAlias6");
+      for (int i = 0; i < fullPaths.size(); i++) {
+        schemaRegion.upsertAliasAndTagsAndAttributes(
+            aliasList.get(i), newTags, newAttributes, new PartialPath(fullPaths.get(i)));
+        checkAliasAndTagsAndAttributes(fullPaths.get(i), aliasList.get(i), newTags, newAttributes);
+      }
+    } catch (Exception e) {
+      logger.error(e.getMessage(), e);
+      Assert.fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void testAddAttributes() {
+    try {
+      prepareTimeseries();
+      Map<String, String> newAttributes =
+          new HashMap<String, String>() {
+            {
+              put("attr2", "new2");
+              put("attr3", "new3");
+            }
+          };
+      schemaRegion.addAttributes(newAttributes, new PartialPath("root.sg.wf01.wt01.v1.s1"));
+      schemaRegion.addAttributes(newAttributes, new PartialPath("root.sg.wf01.aligned_device1.s1"));
+      try {
+        schemaRegion.addAttributes(newAttributes, new PartialPath("root.sg.wf01.wt01.v1.s2"));
+        Assert.fail();
+      } catch (MetadataException e) {
+        // expected
+        Assert.assertTrue(e.getMessage().contains("already has the attribute"));
+      }
+      try {
+        schemaRegion.addAttributes(
+            newAttributes, new PartialPath("root.sg.wf01.aligned_device2.s2"));
+        Assert.fail();
+      } catch (MetadataException e) {
+        // expected
+        Assert.assertTrue(e.getMessage().contains("already has the attribute"));
+      }
+      checkAttributes("root.sg.wf01.wt01.v1.s1", newAttributes);
+      checkAttributes("root.sg.wf01.aligned_device1.s1", newAttributes);
+    } catch (Exception e) {
+      logger.error(e.getMessage(), e);
+      Assert.fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void testAddTags() {
+    try {
+      prepareTimeseries();
+      Map<String, String> newTags =
+          new HashMap<String, String>() {
+            {
+              put("tag2", "new2");
+              put("tag3", "new3");
+            }
+          };
+      schemaRegion.addTags(newTags, new PartialPath("root.sg.wf01.wt01.v1.s1"));
+      schemaRegion.addTags(newTags, new PartialPath("root.sg.wf01.aligned_device1.s1"));
+      try {
+        schemaRegion.addTags(newTags, new PartialPath("root.sg.wf01.wt01.v1.s2"));
+        Assert.fail();
+      } catch (MetadataException e) {
+        // expected
+        Assert.assertTrue(e.getMessage().contains("already has the tag"));
+      }
+      try {
+        schemaRegion.addTags(newTags, new PartialPath("root.sg.wf01.aligned_device2.s2"));
+        Assert.fail();
+      } catch (MetadataException e) {
+        // expected
+        Assert.assertTrue(e.getMessage().contains("already has the tag"));
+      }
+      checkTags("root.sg.wf01.wt01.v1.s1", newTags);
+      checkTags("root.sg.wf01.aligned_device1.s1", newTags);
+    } catch (Exception e) {
+      logger.error(e.getMessage(), e);
+      Assert.fail(e.getMessage());
+    }
+  }
+
+  @Test
+  @Ignore
+  public void testDropTagsOrAttributes() {
+    try {
+      prepareTimeseries();
+      Set<String> keySet = new HashSet<>(Arrays.asList("tag1", "tag2", "attr1", "attr2"));
+      List<String> fullPaths =
+          Arrays.asList(
+              "root.sg.wf01.wt01.v1.s1",
+              "root.sg.wf01.wt01.v1.s2",
+              "root.sg.wf01.aligned_device1.s1",
+              "root.sg.wf01.aligned_device1.s2",
+              "root.sg.wf01.aligned_device2.s1",
+              "root.sg.wf01.aligned_device2.s2");
+      for (String fullPath : fullPaths) {
+        schemaRegion.dropTagsOrAttributes(keySet, new PartialPath(fullPath));
+        checkTags(fullPath, Collections.emptyMap());
+        checkAttributes(fullPath, Collections.emptyMap());
+      }
+    } catch (Exception e) {
+      logger.error(e.getMessage(), e);
+      Assert.fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void testSetTagsOrAttributesValue() {
+    try {
+      prepareTimeseries();
+      Map<String, String> tagsOrAttributesValue =
+          new HashMap<String, String>() {
+            {
+              put("tag1", "new1");
+              put("attr1", "new1");
+            }
+          };
+      List<String> fullPaths =
+          Arrays.asList(
+              "root.sg.wf01.wt01.v1.s1",
+              "root.sg.wf01.wt01.v1.s2",
+              "root.sg.wf01.aligned_device1.s1",
+              "root.sg.wf01.aligned_device1.s2",
+              "root.sg.wf01.aligned_device2.s1",
+              "root.sg.wf01.aligned_device2.s2");
+      List<Boolean> expectException = Arrays.asList(true, false, true, true, false, true);
+      for (int i = 0; i < fullPaths.size(); i++) {
+        try {
+          schemaRegion.setTagsOrAttributesValue(
+              tagsOrAttributesValue, new PartialPath(fullPaths.get(i)));
+          Assert.assertFalse(expectException.get(i));
+        } catch (Exception e) {
+          Assert.assertTrue(expectException.get(i));
+          Assert.assertTrue(e.getMessage().contains("does not have"));
+        }
+      }
+      checkAttributes(
+          "root.sg.wf01.wt01.v1.s2",
+          new HashMap<String, String>() {
+            {
+              put("attr1", "new1");
+              put("attr2", "a2");
+            }
+          });
+      checkTags(
+          "root.sg.wf01.wt01.v1.s2",
+          new HashMap<String, String>() {
+            {
+              put("tag1", "new1");
+              put("tag2", "t2");
+            }
+          });
+      checkAttributes(
+          "root.sg.wf01.aligned_device2.s1",
+          new HashMap<String, String>() {
+            {
+              put("attr1", "new1");
+            }
+          });
+      checkTags(
+          "root.sg.wf01.aligned_device2.s1",
+          new HashMap<String, String>() {
+            {
+              put("tag1", "new1");
+            }
+          });
+    } catch (Exception e) {
+      logger.error(e.getMessage(), e);
+      Assert.fail(e.getMessage());
+    }
+  }
+
+  @Test
+  public void testRenameTagOrAttributeKey() {
+    try {
+      prepareTimeseries();
+      try {
+        schemaRegion.renameTagOrAttributeKey(
+            "attr1", "attr2", new PartialPath("root.sg.wf01.wt01.v1.s2"));
+        Assert.fail();
+      } catch (Exception e) {
+        Assert.assertTrue(e.getMessage().contains("already has a tag/attribute named"));
+      }
+      try {
+        schemaRegion.renameTagOrAttributeKey(
+            "attr3", "newAttr3", new PartialPath("root.sg.wf01.wt01.v1.s2"));
+        Assert.fail();
+      } catch (Exception e) {
+        Assert.assertTrue(e.getMessage().contains("does not have tag/attribute"));
+      }
+      schemaRegion.renameTagOrAttributeKey(
+          "attr1", "newAttr1", new PartialPath("root.sg.wf01.wt01.v1.s2"));
+      schemaRegion.renameTagOrAttributeKey(
+          "tag1", "newTag1", new PartialPath("root.sg.wf01.wt01.v1.s2"));
+      schemaRegion.renameTagOrAttributeKey(
+          "attr1", "newAttr1", new PartialPath("root.sg.wf01.aligned_device2.s1"));
+      schemaRegion.renameTagOrAttributeKey(
+          "tag1", "newTag1", new PartialPath("root.sg.wf01.aligned_device2.s1"));
+      checkAttributes(
+          "root.sg.wf01.wt01.v1.s2",
+          new HashMap<String, String>() {
+            {
+              put("newAttr1", "a1");
+              put("attr2", "a2");
+            }
+          });
+      checkTags(
+          "root.sg.wf01.wt01.v1.s2",
+          new HashMap<String, String>() {
+            {
+              put("newTag1", "t1");
+              put("tag2", "t2");
+            }
+          });
+      checkAttributes(
+          "root.sg.wf01.aligned_device2.s1",
+          new HashMap<String, String>() {
+            {
+              put("newAttr1", "a1");
+            }
+          });
+      checkTags(
+          "root.sg.wf01.aligned_device2.s1",
+          new HashMap<String, String>() {
+            {
+              put("newTag1", "t1");
+            }
+          });
+    } catch (Exception e) {
+      logger.error(e.getMessage(), e);
+      Assert.fail(e.getMessage());
+    }
+  }
 }
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
new file mode 100644
index 0000000000..51c2c3deea
--- /dev/null
+++ b/server/src/test/java/org/apache/iotdb/db/metadata/schemaRegion/SchemaRegionTestUtil.java
@@ -0,0 +1,107 @@
+/*
+ * 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.db.metadata.schemaRegion;
+
+import org.apache.iotdb.commons.exception.MetadataException;
+import org.apache.iotdb.commons.path.PartialPath;
+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.tsfile.file.metadata.enums.CompressionType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import java.util.List;
+import java.util.Map;
+
+public class SchemaRegionTestUtil {
+
+  public static void createTimeseries(
+      ISchemaRegion schemaRegion,
+      String fullPath,
+      TSDataType dataType,
+      TSEncoding encoding,
+      CompressionType compressor,
+      Map<String, String> props,
+      Map<String, String> tags,
+      Map<String, String> attributes,
+      String alias)
+      throws MetadataException {
+    schemaRegion.createTimeseries(
+        new CreateTimeSeriesPlanImpl(
+            new PartialPath(fullPath),
+            dataType,
+            encoding,
+            compressor,
+            props,
+            tags,
+            attributes,
+            alias),
+        -1);
+  }
+
+  public static void createTimeseries(
+      ISchemaRegion schemaRegion,
+      List<String> fullPaths,
+      List<TSDataType> dataTypes,
+      List<TSEncoding> encodings,
+      List<CompressionType> compressors,
+      List<Map<String, String>> props,
+      List<Map<String, String>> tags,
+      List<Map<String, String>> attributes,
+      List<String> alias)
+      throws MetadataException {
+    for (int i = 0; i < fullPaths.size(); i++) {
+      schemaRegion.createTimeseries(
+          new CreateTimeSeriesPlanImpl(
+              new PartialPath(fullPaths.get(i)),
+              dataTypes.get(i),
+              encodings.get(i),
+              compressors.get(i),
+              props == null ? null : props.get(i),
+              tags == null ? null : tags.get(i),
+              attributes == null ? null : attributes.get(i),
+              alias == null ? null : alias.get(i)),
+          -1);
+    }
+  }
+
+  public static void createAlignedTimeseries(
+      ISchemaRegion schemaRegion,
+      String devicePath,
+      List<String> measurements,
+      List<TSDataType> dataTypes,
+      List<TSEncoding> encodings,
+      List<CompressionType> compressors,
+      List<Map<String, String>> tags,
+      List<Map<String, String>> attributes,
+      List<String> alias)
+      throws MetadataException {
+    schemaRegion.createAlignedTimeSeries(
+        new CreateAlignedTimeSeriesPlanImpl(
+            new PartialPath(devicePath),
+            measurements,
+            dataTypes,
+            encodings,
+            compressors,
+            alias,
+            tags,
+            attributes));
+  }
+}