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 152c10bf67 [IOTDB-5882] Support create empty schema template (#9858)
152c10bf67 is described below

commit 152c10bf67f135720259ea69668df1dc48c97c9f
Author: Marcos_Zyk <[email protected]>
AuthorDate: Tue May 16 14:09:50 2023 +0800

    [IOTDB-5882] Support create empty schema template (#9858)
---
 .../org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4   |  2 +-
 .../iotdb/db/it/schema/IoTDBSchemaTemplateIT.java  | 45 ++++++++++++++++++++++
 2 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4 
b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
index 4a95f1a812..2da40dd185 100644
--- a/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
+++ b/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4
@@ -222,7 +222,7 @@ tagWhereClause
 // ---- Create Schema Template
 createSchemaTemplate
     : CREATE SCHEMA TEMPLATE templateName=identifier
-    ALIGNED? LR_BRACKET templateMeasurementClause (COMMA 
templateMeasurementClause)* RR_BRACKET
+    ALIGNED? (LR_BRACKET templateMeasurementClause (COMMA 
templateMeasurementClause)* RR_BRACKET)?
     ;
 
 templateMeasurementClause
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 173e744ba4..54c56da781 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
@@ -726,4 +726,49 @@ public class IoTDBSchemaTemplateIT extends 
AbstractSchemaIT {
       Assert.assertTrue(expectedResult.isEmpty());
     }
   }
+
+  @Test
+  public void testEmptySchemaTemplate() throws Exception {
+    try (Connection connection = EnvFactory.getEnv().getConnection();
+        Statement statement = connection.createStatement()) {
+      // create empty schema template
+      statement.execute("create schema template e_t");
+      // set schema template
+      statement.execute("SET SCHEMA TEMPLATE e_t TO root.sg1");
+      try (ResultSet resultSet = statement.executeQuery("show nodes in schema 
template e_t")) {
+        Assert.assertFalse(resultSet.next());
+      }
+
+      try (ResultSet resultSet = statement.executeQuery("show paths set schema 
template e_t")) {
+        Assert.assertTrue(resultSet.next());
+        Assert.assertFalse(resultSet.next());
+      }
+
+      statement.execute("alter schema template e_t add(s1 int32)");
+      statement.execute("insert into root.sg1.d(time, s2, s3) values(1, 1, 
1)");
+
+      Set<String> expectedResult =
+          new HashSet<>(
+              Arrays.asList(
+                  "root.sg1.d.s1,INT32,RLE,SNAPPY",
+                  "root.sg1.d.s2,FLOAT,GORILLA,SNAPPY",
+                  "root.sg1.d.s3,FLOAT,GORILLA,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());
+    }
+  }
 }

Reply via email to