You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/01/24 11:12:28 UTC

[GitHub] [iotdb] JackieTien97 commented on a change in pull request #4900: [IOTDB-2380] Add SQL for show and drop schema template

JackieTien97 commented on a change in pull request #4900:
URL: https://github.com/apache/iotdb/pull/4900#discussion_r790625909



##########
File path: docs/UserGuide/Operate-Metadata/Template.md
##########
@@ -19,42 +19,192 @@
 
 -->
 
-## Schema Template
+# Schema Template
 
 IoTDB supports the schema template function, enabling different entities of the same type to share metadata, reduce the memory usage of metadata, and simplify the management of numerous entities and measurements.
 
-### Create Schema Template
+Note: The `schema` keyword in the following statements can be omitted.
 
-The SQL Statement for creating schema template is as follow:
+## Create Schema Template
 
+The SQL syntax for creating a metadata template is as follows:
+
+```sql
+CREATE SCHEMA? TEMPLATE <templateName> ALIGNED '(' templateMeasurementClause [',' templateMeasurementClause]+ ')'
+
+templateMeasurementClause
+    : <measurementId> <attributeClauses> # single measurement
+    | <deviceId> ALIGNED '(' <measurementId> <attributeClauses> [',' <measurementId> <attributeClauses>]+ ')' # a group of aligned measurements
+    ;
+```
+
+**Example 1:** Create a template containing two non-aligned timeseires
+
+```shell
+IoTDB> create schema template temp1 (temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY)
 ```
-IoTDB> create schema template temp1(GPS(lat FLOAT encoding=Gorilla, lon FLOAT encoding=Gorilla compression=SNAPPY), status BOOLEAN encoding=PLAIN compression=SNAPPY)
+
+**Example 2:** Create a template containing a group of aligned timeseires
+
+```shell
+IoTDB> create schema template temp2 aligned (lat FLOAT encoding=Gorilla, lon FLOAT encoding=Gorilla)
+```
+
+**Example 3:** Creating a template that mixes aligned and non-aligned timeseires
+
+```shell
+IoTDB> create schema template temp3 (GPS aligned (lat FLOAT encoding=Gorilla, lon FLOAT encoding=Gorilla compression=SNAPPY), status BOOLEAN encoding=PLAIN compression=SNAPPY)
 ```
 
 The` lat` and `lon` measurements under the `GPS` device are aligned.
 
-### Set Schema Template
+## Set Schema Template
 
 The SQL Statement for setting schema template is as follow:
 
-```
+```shell
 IoTDB> set schema template temp1 to root.ln.wf01
 ```
 
 After setting the schema template, you can insert data into the timeseries. For example, suppose there's a storage group root.ln and temp1 has been set to root.ln.wf01, then timeseries like root.ln.wf01.GPS.lat and root.ln.wf01.status are available and data points can be inserted.
 
 **Attention**: Before inserting data, timeseries defined by the schema template will not be created. You can use the following SQL statement to create the timeseries before inserting data:
 
-```
+```shell
 IoTDB> create timeseries of schema template on root.ln.wf01
 ```
 
-### Uset Schema Template
+**Example:** Execute the following statement
+```shell
+set schema template temp1 to root.sg1.d1
+set schema template temp2 to root.sg1.d2
+set schema template temp3 to root.sg1.d3
+create timeseries of schema template on root.sg1.d1
+create timeseries of schema template on root.sg1.d2
+create timeseries of schema template on root.sg1.d3
+````
+
+Show the time series:
+```sql
+show timeseries root.sg1.**
+````
+
+```shell
++-----------------------+-----+-------------+--------+--------+-----------+----+----------+
+|             timeseries|alias|storage group|dataType|encoding|compression|tags|attributes|
++-----------------------+-----+-------------+--------+--------+-----------+----+----------+
+|root.sg1.d1.temperature| null|     root.sg1|   FLOAT|     RLE|     SNAPPY|null|      null|
+|     root.sg1.d1.status| null|     root.sg1| BOOLEAN|   PLAIN|     SNAPPY|null|      null|
+|        root.sg1.d2.lon| null|     root.sg1|   FLOAT| GORILLA|     SNAPPY|null|      null|
+|        root.sg1.d2.lat| null|     root.sg1|   FLOAT| GORILLA|     SNAPPY|null|      null|
+|    root.sg1.d3.GPS.lon| null|     root.sg1|   FLOAT| GORILLA|     SNAPPY|null|      null|
+|    root.sg1.d3.GPS.lat| null|     root.sg1|   FLOAT| GORILLA|     SNAPPY|null|      null|
+|     root.sg1.d3.status| null|     root.sg1| BOOLEAN|   PLAIN|     SNAPPY|null|      null|
++-----------------------+-----+-------------+--------+--------+-----------+----+----------+
+````
+
+Show the devices:
+```sql
+show devices root.sg1.**
+````
+
+```shell
++---------------+---------+
+|        devices|isAligned|
++---------------+---------+
+|    root.sg1.d1|    false|
+|    root.sg1.d2|     true|
+|    root.sg1.d3|    false|
+|root.sg1.d3.GPS|     true|
++---------------+---------+
+````
+
+## Show Schema Template
+
+- Show all schema templates
+
+The SQL statement looks like this:
+
+```shell
+IoTDB> show schema templates on root.ln.wf01
+````
+
+The execution result is as follows:
+```shell
++-------------+
+|template name|
++-------------+
+|        temp2|
+|        temp3|
+|        temp1|
++-------------+
+````
+
+- Show nodes under in schema template
+
+The SQL statement looks like this:
+
+```shell
+IoTDB> show nodes in schema template temp3
+````
+
+The execution result is as follows:
+```shell
++-----------+--------+--------+-----------+
+|child nodes|dataType|encoding|compression|
++-----------+--------+--------+-----------+
+|    GPS.lon|   FLOAT| GORILLA|     SNAPPY|
+|    GPS.lat|   FLOAT| GORILLA|     SNAPPY|
+|     status| BOOLEAN|   PLAIN|     SNAPPY|
++-----------+--------+--------+-----------+
+````
+
+- Show the path prefix where a schema template is set
+
+```shell
+IoTDB> show paths set schema template temp1
+````
+
+The execution result is as follows:
+```shell
++------------+
+| child paths|
++------------+
+|root.ln.wf01|
++------------+
+````
+
+- Show the path prefix where a schema template is used (i.e. the time series has been created)
+
+```shell
+IoTDB> show paths using schema template temp1
+````
+
+The execution result is as follows:
+```shell
++------------+
+| child paths|
++------------+
+|root.ln.wf01|
++------------+

Review comment:
       Better to make the example same as the above.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org