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.
Note: The schema
keyword in the following statements can be omitted.
Create Schema Template
The SQL syntax for creating a schema template is as follows:
CREATE SCHEMA? TEMPLATE <templateName> ALIGNED? '(' <measurementId> <attributeClauses> [',' <measurementId> <attributeClauses>]+ ')'
Example 1: Create a template containing two non-aligned timeseires
IoTDB> create schema template t1 (temperature FLOAT encoding=RLE, status BOOLEAN encoding=PLAIN compression=SNAPPY)
Example 2: Create a template containing a group of aligned timeseires
IoTDB> create schema template t2 aligned (lat FLOAT encoding=Gorilla, lon FLOAT encoding=Gorilla)
The lat
and lon
measurements are aligned.
Set Schema Template
The SQL Statement for setting schema template is as follow:
IoTDB> set schema template t1 to root.sg1.d1
After setting the schema template, you can insert data into the timeseries. For example, suppose there's a storage group root.sg1 and t1 has been set to root.sg1.d1, then timeseries like root.sg1.d1.temperature and root.sg1.d1.status are available and data points can be inserted.
Please notice that, we strongly recommend NOT setting templates on the nodes above the storage group to accommodate future updates and collaboration between modules.
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:
IoTDB> create timeseries of schema template on root.sg1.d1
Example: Execute the following statement
set schema template t1 to root.sg1.d1
set schema template t2 to root.sg1.d2
create timeseries of schema template on root.sg1.d1
create timeseries of schema template on root.sg1.d2
Show the time series:
show timeseries root.sg1.**
+-----------------------+-----+-------------+--------+--------+-----------+----+----------+--------+-------------------+
| timeseries|alias|storage group|dataType|encoding|compression|tags|attributes|deadband|deadband parameters|
+-----------------------+-----+-------------+--------+--------+-----------+----+----------+--------+-------------------+
|root.sg1.d1.temperature| null| root.sg1| FLOAT| RLE| SNAPPY|null| null| null| null|
| root.sg1.d1.status| null| root.sg1| BOOLEAN| PLAIN| SNAPPY|null| null| null| null|
| root.sg1.d2.lon| null| root.sg1| FLOAT| GORILLA| SNAPPY|null| null| null| null|
| root.sg1.d2.lat| null| root.sg1| FLOAT| GORILLA| SNAPPY|null| null| null| null|
+-----------------------+-----+-------------+--------+--------+-----------+----+----------+--------+-------------------+
Show the devices:
show devices root.sg1.**
+---------------+---------+
| devices|isAligned|
+---------------+---------+
| root.sg1.d1| false|
| root.sg1.d2| true|
+---------------+---------+
Show Schema Template
- Show all schema templates
The SQL statement looks like this:
IoTDB> show schema templates
The execution result is as follows:
+-------------+
|template name|
+-------------+
| t2|
| t1|
+-------------+
- Show nodes under in schema template
The SQL statement looks like this:
IoTDB> show nodes in schema template t1
The execution result is as follows:
+-----------+--------+--------+-----------+
|child nodes|dataType|encoding|compression|
+-----------+--------+--------+-----------+
|temperature| FLOAT| RLE| SNAPPY|
| status| BOOLEAN| PLAIN| SNAPPY|
+-----------+--------+--------+-----------+
- Show the path prefix where a schema template is set
IoTDB> show paths set schema template t1
The execution result is as follows:
+-----------+
|child paths|
+-----------+
|root.sg1.d1|
+-----------+
- Show the path prefix where a schema template is used (i.e. the time series has been created)
IoTDB> show paths using schema template t1
The execution result is as follows:
+-----------+
|child paths|
+-----------+
|root.sg1.d1|
+-----------+
Deactivate SchemaTemplate
If any data points had been inserted into the timeseries concatenated by the path of the node and measurements inside activated template, or create timeseries of schema template
had been issued, you should deactivate template on nodes before unset tempalte upon them.
IoTDB> deactivate schema template t1 from root.sg1.d1
This statement will detele corresponding data points as well.
Unset Schema Template
The SQL Statement for unsetting schema template is as follow:
IoTDB> unset schema template t1 from root.sg1.d1
Drop Schema Template
The SQL Statement for dropping schema template is as follow:
IoTDB> drop schema template t1
Attention: Dropping an already set template is not supported.