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 2023/04/27 07:13:58 UTC

[iotdb] branch master updated: [IOTDB-5826] Fix schema query with * cannot display satisfied template series (#9723)

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 56bcde6d15 [IOTDB-5826] Fix schema query with * cannot display satisfied template series (#9723)
56bcde6d15 is described below

commit 56bcde6d15db13d3a0071420a3ce7ae9ceb3effd
Author: Chen YZ <43...@users.noreply.github.com>
AuthorDate: Thu Apr 27 15:13:51 2023 +0800

    [IOTDB-5826] Fix schema query with * cannot display satisfied template series (#9723)
---
 .../iotdb/db/it/schema/IoTDBSchemaTemplateIT.java  | 61 ++++++++++++++++++++++
 .../metadata/template/ClusterTemplateManager.java  | 10 ++--
 2 files changed, 64 insertions(+), 7 deletions(-)

diff --git a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBSchemaTemplateIT.java b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBSchemaTemplateIT.java
index 670e219899..9442c47424 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBSchemaTemplateIT.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBSchemaTemplateIT.java
@@ -656,4 +656,65 @@ public class IoTDBSchemaTemplateIT extends AbstractSchemaIT {
       statement.execute("CREATE TIMESERIES root.sg1.d2.s INT32");
     }
   }
+
+  @Test
+  public void testShowTemplateSeriesWithFuzzyQuery() throws Exception {
+    // test create schema template repeatedly
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      // set schema template
+      statement.execute("SET SCHEMA TEMPLATE t1 TO root.sg1");
+      statement.execute("SET SCHEMA TEMPLATE t2 TO root.sg2");
+      statement.execute("SET SCHEMA TEMPLATE t3 TO root.sg3");
+      // activate schema template
+      statement.execute("create timeseries using schema template on root.sg1.d1");
+      statement.execute("create timeseries using schema template on root.sg2.d2");
+      statement.execute("create timeseries using schema template on root.sg3.d3");
+
+      Set<String> expectedResult =
+          new HashSet<>(
+              Arrays.asList(
+                  "root.sg1.d1.s1,INT64,RLE,SNAPPY",
+                  "root.sg1.d1.s2,DOUBLE,GORILLA,SNAPPY",
+                  "root.sg2.d2.s1,INT64,RLE,SNAPPY",
+                  "root.sg2.d2.s2,DOUBLE,GORILLA,SNAPPY",
+                  "root.sg3.d3.s1,INT64,RLE,SNAPPY"));
+
+      try (ResultSet resultSet = statement.executeQuery("SHOW TIMESERIES root.sg*.*.s*")) {
+        while (resultSet.next()) {
+          String actualResult =
+              resultSet.getString(ColumnHeaderConstant.TIMESERIES)
+                  + ","
+                  + resultSet.getString(ColumnHeaderConstant.DATATYPE)
+                  + ","
+                  + resultSet.getString(ColumnHeaderConstant.ENCODING)
+                  + ","
+                  + resultSet.getString(ColumnHeaderConstant.COMPRESSION);
+          Assert.assertTrue(expectedResult.contains(actualResult));
+          expectedResult.remove(actualResult);
+        }
+      }
+      Assert.assertTrue(expectedResult.isEmpty());
+      expectedResult =
+          new HashSet<>(
+              Arrays.asList(
+                  "root.sg1.d1.s1,INT64,RLE,SNAPPY", "root.sg1.d1.s2,DOUBLE,GORILLA,SNAPPY"));
+
+      try (ResultSet resultSet = statement.executeQuery("SHOW TIMESERIES root.sg1.d1.s*")) {
+        while (resultSet.next()) {
+          String actualResult =
+              resultSet.getString(ColumnHeaderConstant.TIMESERIES)
+                  + ","
+                  + resultSet.getString(ColumnHeaderConstant.DATATYPE)
+                  + ","
+                  + resultSet.getString(ColumnHeaderConstant.ENCODING)
+                  + ","
+                  + resultSet.getString(ColumnHeaderConstant.COMPRESSION);
+          Assert.assertTrue(expectedResult.contains(actualResult));
+          expectedResult.remove(actualResult);
+        }
+      }
+      Assert.assertTrue(expectedResult.isEmpty());
+    }
+  }
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/metadata/template/ClusterTemplateManager.java b/server/src/main/java/org/apache/iotdb/db/metadata/template/ClusterTemplateManager.java
index b618106965..bfbb1644ca 100644
--- a/server/src/main/java/org/apache/iotdb/db/metadata/template/ClusterTemplateManager.java
+++ b/server/src/main/java/org/apache/iotdb/db/metadata/template/ClusterTemplateManager.java
@@ -380,13 +380,9 @@ public class ClusterTemplateManager implements ITemplateManager {
     // and the following logic is equivalent with the above expression
 
     String measurement = pathPattern.getTailNode();
-    if (measurement.equals(MULTI_LEVEL_PATH_WILDCARD)
-        || measurement.equals(ONE_LEVEL_PATH_WILDCARD)) {
-      return pathPattern.overlapWith(
-              pathSetTemplate
-                  .concatNode(MULTI_LEVEL_PATH_WILDCARD)
-                  .concatNode(ONE_LEVEL_PATH_WILDCARD))
-          || pathPattern.overlapWith(pathSetTemplate.concatNode(ONE_LEVEL_PATH_WILDCARD));
+    if (measurement.contains(ONE_LEVEL_PATH_WILDCARD)) {
+      // if measurement is wildcard, e.g. root.sg.d1.**, root.sg.d1.*, root.sg.d1.s*
+      return pathPattern.overlapWithFullPathPrefix(pathSetTemplate);
     }
 
     if (template.hasSchema(measurement)) {