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/08/10 14:04:35 UTC

[iotdb] branch rel/0.13 updated: [To rel/0.13][ISSUE-6937]Add alignment flag for single measurement template #6950

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

zyk pushed a commit to branch rel/0.13
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/rel/0.13 by this push:
     new e5510fe80a [To rel/0.13][ISSUE-6937]Add alignment flag for single measurement template #6950
e5510fe80a is described below

commit e5510fe80a4ec095f557f7c3b2f48ed4e3c34343
Author: ZhaoXin <x_...@163.com>
AuthorDate: Wed Aug 10 22:04:30 2022 +0800

    [To rel/0.13][ISSUE-6937]Add alignment flag for single measurement template #6950
    
    [To rel/0.13][ISSUE-6937]Add alignment flag for single measurement template #6950
---
 .../apache/iotdb/session/template/TemplateUT.java  | 58 ++++++++++++++++++++++
 .../iotdb/db/metadata/template/Template.java       |  2 +-
 .../db/qp/physical/sys/CreateTemplatePlan.java     | 37 ++++++++++----
 3 files changed, 85 insertions(+), 12 deletions(-)

diff --git a/integration/src/test/java/org/apache/iotdb/session/template/TemplateUT.java b/integration/src/test/java/org/apache/iotdb/session/template/TemplateUT.java
index 9adcbbdc4e..516c409a06 100644
--- a/integration/src/test/java/org/apache/iotdb/session/template/TemplateUT.java
+++ b/integration/src/test/java/org/apache/iotdb/session/template/TemplateUT.java
@@ -41,6 +41,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.time.ZoneId;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
@@ -650,6 +651,63 @@ public class TemplateUT {
     }
   }
 
+  @Test
+  public void testSingleMeasurementTemplateAlignment() throws IoTDBConnectionException {
+    try {
+      List<String> str_list = new ArrayList<>();
+      str_list.add("at1");
+      List<TSDataType> type_list = new ArrayList<>();
+      type_list.add(TSDataType.FLOAT);
+      List<TSEncoding> encoding_list = new ArrayList<>();
+      encoding_list.add(TSEncoding.GORILLA);
+      List<CompressionType> compression_type_list = new ArrayList<>();
+      compression_type_list.add(CompressionType.SNAPPY);
+      session.createSchemaTemplate(
+          "t1", str_list, type_list, encoding_list, compression_type_list, true);
+      session.addAlignedMeasurementInTemplate(
+          "t1", "at2", TSDataType.FLOAT, TSEncoding.GORILLA, CompressionType.SNAPPY);
+      session.addAlignedMeasurementInTemplate(
+          "t1", "at3", TSDataType.FLOAT, TSEncoding.GORILLA, CompressionType.SNAPPY);
+
+      session.executeNonQueryStatement("set template t1 to root.SG1");
+      session.executeNonQueryStatement("create timeseries of schema template on root.SG1.a");
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail();
+    } finally {
+      if (session != null) {
+        session.close();
+      }
+    }
+
+    try {
+      EnvironmentUtils.restartDaemon();
+    } catch (Exception e) {
+      Assert.fail();
+    }
+
+    try {
+      session = new Session("127.0.0.1", 6667, "root", "root", 16);
+      session.open();
+
+      SessionDataSet res = session.executeQueryStatement("show devices");
+      if (res.hasNext()) {
+        Assert.assertEquals("true", res.next().getFields().get(1).toString());
+      }
+
+      res = session.executeQueryStatement("show timeseries");
+      int cnt = 0;
+      while (res.hasNext()) {
+        cnt++;
+        res.next();
+      }
+      assertEquals(3, cnt);
+    } catch (Exception e) {
+      e.printStackTrace();
+      fail();
+    }
+  }
+
   private Template getTemplate(String name) throws StatementExecutionException {
     Template sessionTemplate = new Template(name, true);
     TemplateNode iNodeGPS = new InternalNode("GPS", false);
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/template/Template.java b/server/src/main/java/org/apache/iotdb/db/metadata/template/Template.java
index c92663177b..def651c0b4 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/template/Template.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/template/Template.java
@@ -89,7 +89,7 @@ public class Template {
         isAlign = true;
       } else {
         // If sublist of measurements has only one item,
-        // but it share prefix with other aligned sublist, it will be aligned too
+        // but it shares prefix with other aligned sublist, it will be aligned too
         String[] thisMeasurement =
             MetaUtils.splitPathToDetachedPath(plan.getMeasurements().get(i).get(0));
         String thisPrefix =
diff --git a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/CreateTemplatePlan.java b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/CreateTemplatePlan.java
index b05030bb58..dfbce3c17a 100644
--- a/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/CreateTemplatePlan.java
+++ b/server/src/main/java/org/apache/iotdb/db/qp/physical/sys/CreateTemplatePlan.java
@@ -51,8 +51,13 @@ public class CreateTemplatePlan extends PhysicalPlan {
   TSDataType[][] dataTypes;
   TSEncoding[][] encodings;
   CompressionType[][] compressors;
-  // constant to help resolve serialized sequence
+
+  // Flags for compatible issues, located at where to put size of schemaNames
+  // NEW_PLAN means no schemaNames, but not directly aligned
   private static final int NEW_PLAN = -1;
+  // directly-alignment-flag to indicate directly aligned, with no schemaNames as well
+  // NECESSARY for occasions where only ONE measurement inside a template
+  private static final int DIR_ALI_FLG = -2;
 
   public CreateTemplatePlan() {
     super(OperatorType.CREATE_TEMPLATE);
@@ -286,9 +291,13 @@ public class CreateTemplatePlan extends PhysicalPlan {
 
     ReadWriteIOUtils.write(name, buffer);
 
-    // write NEW_PLAN as flag to note that there is no schemaNames and new nested list for
-    // compressors
-    ReadWriteIOUtils.write(NEW_PLAN, buffer);
+    if (alignedDeviceId != null && alignedDeviceId.contains("")) {
+      // indicate template is directly aligned, no schemaNames of course
+      ReadWriteIOUtils.write(DIR_ALI_FLG, buffer);
+    } else {
+      // indicate that there is no schemaNames and a nested list for compressors
+      ReadWriteIOUtils.write(NEW_PLAN, buffer);
+    }
 
     // measurements
     ReadWriteIOUtils.write(measurements.length, buffer);
@@ -332,14 +341,16 @@ public class CreateTemplatePlan extends PhysicalPlan {
   @Override
   @SuppressWarnings("Duplicates")
   public void deserialize(ByteBuffer buffer) {
-    boolean isFormerSerialized;
+    boolean isFormerSerialized = false;
     name = ReadWriteIOUtils.readString(buffer);
 
     int size = ReadWriteIOUtils.readInt(buffer);
 
-    if (size == NEW_PLAN) {
-      isFormerSerialized = false;
-    } else {
+    if (size == DIR_ALI_FLG) {
+      // no action for NEW_PLAN
+      alignedDeviceId = new HashSet<>();
+      alignedDeviceId.add("");
+    } else if (size > 0) {
       // deserialize schemaNames
       isFormerSerialized = true;
       schemaNames = new String[size];
@@ -416,9 +427,13 @@ public class CreateTemplatePlan extends PhysicalPlan {
 
     ReadWriteIOUtils.write(name, stream);
 
-    // write NEW_PLAN as flag to note that there is no schemaNames and new nested list for
-    // compressors
-    ReadWriteIOUtils.write(NEW_PLAN, stream);
+    if (alignedDeviceId != null && alignedDeviceId.contains("")) {
+      // indicate template is directly aligned, no schemaNames of course
+      ReadWriteIOUtils.write(DIR_ALI_FLG, stream);
+    } else {
+      // indicate that there is no schemaNames and a nested list for compressors
+      ReadWriteIOUtils.write(NEW_PLAN, stream);
+    }
 
     // measurements
     ReadWriteIOUtils.write(measurements.length, stream);