DDL (Data Definition Language)

Create Storage Group

According to the storage model we can set up the corresponding storage group. The SQL statements for creating storage groups are as follows:

  1. IoTDB > set storage group to root.ln
  2. IoTDB > set storage group to root.sgcc

We can thus create two storage groups using the above two SQL statements.

It is worth noting that when the path itself or the parent/child layer of the path is already set as a storage group, the path is then not allowed to be set as a storage group. For example, it is not feasible to set root.ln.wf01 as a storage group when there exist two storage groups root.ln and root.sgcc. The system will give the corresponding error prompt as shown below:

  1. IoTDB> set storage group to root.ln.wf01
  2. Msg: org.apache.iotdb.exception.MetadataErrorException: org.apache.iotdb.exception.PathErrorException: The prefix of root.ln.wf01 has been set to the storage group.

Show Storage Group

After the storage group is created, we can use the SHOW STORAGE GROUP statement to view all the storage groups. The SQL statement is as follows:

  1. IoTDB> show storage group

The result is as follows:

DDL (Data Definition Language) - 图1

Create Timeseries

According to the storage model selected before, we can create corresponding timeseries in the two storage groups respectively. The SQL statements for creating timeseries are as follows:

  1. IoTDB > create timeseries root.ln.wf01.wt01.status with datatype=BOOLEAN,encoding=PLAIN
  2. IoTDB > create timeseries root.ln.wf01.wt01.temperature with datatype=FLOAT,encoding=RLE
  3. IoTDB > create timeseries root.ln.wf02.wt02.hardware with datatype=TEXT,encoding=PLAIN
  4. IoTDB > create timeseries root.ln.wf02.wt02.status with datatype=BOOLEAN,encoding=PLAIN
  5. IoTDB > create timeseries root.sgcc.wf03.wt01.status with datatype=BOOLEAN,encoding=PLAIN
  6. IoTDB > create timeseries root.sgcc.wf03.wt01.temperature with datatype=FLOAT,encoding=RLE

It is worth noting that when in the CRATE TIMESERIES statement the encoding method conflicts with the data type, the system will give the corresponding error prompt as shown below:

  1. IoTDB> create timeseries root.ln.wf02.wt02.status WITH DATATYPE=BOOLEAN, ENCODING=TS_2DIFF
  2. error: encoding TS_2DIFF does not support BOOLEAN

Please refer to Encoding for correspondence between data type and encoding.

Tag and attribute management

We can also add an alias, extra tag and attribute information while creating one timeseries. The SQL statements for creating timeseries with extra tag and attribute information are extended as follows:

  1. create timeseries root.turbine.d1.s1(temprature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY tags(tag1=v1, tag2=v2) attributes(attr1=v1, attr2=v2)

The temprature in the brackets is an alias for the sensor s1. So we can use temprature to replace s1 anywhere.

Notice that the size of the extra tag and attribute information shouldn’t exceed the tag_attribute_total_size.

The only difference between tag and attribute is that we will maintain an inverted index on the tag, so we can use tag property in the show timeseries where clause which you can see in the following Show Timeseries section.

UPDATE TAG OPERATION

We can update the tag information after creating it as following:

  • Rename the tag/attribute key
  1. ALTER timeseries root.turbine.d1.s1 RENAME tag1 TO newTag1
  • reset the tag/attribute value
  1. ALTER timeseries root.turbine.d1.s1 SET tag1=newV1, attr1=newV1
  • delete the existing tag/attribute
  1. ALTER timeseries root.turbine.d1.s1 DROP tag1, tag2
  • add new tags
  1. ALTER timeseries root.turbine.d1.s1 ADD TAGS tag3=v3, tag4=v4
  • add new attributes
  1. ALTER timeseries root.turbine.d1.s1 ADD ATTRIBUTES attr3=v3, attr4=v4
  • upsert alias, tags and attributes

add alias or a new key-value if the alias or key doesn’t exist, otherwise, update the old one with new value.

  1. ALTER timeseries root.turbine.d1.s1 UPSERT ALIAS=newAlias TAGS(tag3=v3, tag4=v4) ATTRIBUTES(attr3=v3, attr4=v4)

Show Timeseries

  • SHOW TIMESERIES prefixPath? showWhereClause? limitClause?

    There are three optional clauses could be added behind SHOW TIMESERIES, return information of time series

Timeseries information includes: timeseries path, alias of measurement, storage group it belongs to, data type, encoding type, compression type, tags and attributes.

Examples:

  • SHOW TIMESERIES

    presents all timeseries information in JSON form

  • SHOW TIMESERIES <Path>

    returns all timeseries information under the given <Path>. <Path> needs to be a prefix path or a path with star or a timeseries path. SQL statements are as follows:

  1. IoTDB> show timeseries root
  2. IoTDB> show timeseries root.ln

The results are shown below respectively:

DDL (Data Definition Language) - 图2

DDL (Data Definition Language) - 图3

  • SHOW TIMESERIES (<PrefixPath>)? WhereClause

    returns all the timeseries information that satisfy the where condition and start with the prefixPath SQL statements are as follows:

  1. show timeseries root.ln where unit=c
  2. show timeseries root.ln where description contains 'test1'

The results are shown below respectly:

DDL (Data Definition Language) - 图4

Notice that, we only support one condition in the where clause. Either it’s an equal filter or it is an contains filter. In both case, the property in the where condition must be a tag.

  • SHOW TIMESERIES LIMIT INT OFFSET INT

    returns all the timeseries information start from the offset and limit the number of series returned

It is worth noting that when the queried path does not exist, the system will return no timeseries.

Show Child Paths

  1. SHOW CHILD PATHS prefixPath

Return all child paths of the prefixPath, the prefixPath could contains *.

Example:

  • return the child paths of root.ln:show child paths root.ln
  1. +------------+
  2. | child paths|
  3. +------------+
  4. |root.ln.wf01|
  5. |root.ln.wf02|
  6. +------------+
  • get all paths in form of root.xx.xx.xx:show child paths root.*.*
  1. +---------------+
  2. | child paths|
  3. +---------------+
  4. |root.ln.wf01.s1|
  5. |root.ln.wf02.s2|
  6. +---------------+

Count Timeseries

IoTDB is able to use COUNT TIMESERIES <Path> to count the number of timeseries in the path. SQL statements are as follows:

  1. IoTDB > COUNT TIMESERIES root
  2. IoTDB > COUNT TIMESERIES root.ln
  3. IoTDB > COUNT TIMESERIES root.ln.*.*.status
  4. IoTDB > COUNT TIMESERIES root.ln.wf01.wt01.status

Besides, LEVEL could be defined to show count the number of timeseries of each node at the given level in current Metadata Tree. This could be used to query the number of sensors under each device. The grammar is: COUNT TIMESERIES <Path> GROUP BY LEVEL=<INTEGER>.

For example, if there are several timeseires (use show timeseries to show all timeseries):

DDL (Data Definition Language) - 图5

Then the Metadata Tree will be as below:

DDL (Data Definition Language) - 图6

As can be seen, root is considered as LEVEL=0. So when you enter statements such as:

  1. IoTDB > COUNT TIMESERIES root GROUP BY LEVEL=1
  2. IoTDB > COUNT TIMESERIES root.ln GROUP BY LEVEL=2
  3. IoTDB > COUNT TIMESERIES root.ln.wf01 GROUP BY LEVEL=2

You will get following results:

DDL (Data Definition Language) - 图7

Note: The path of timeseries is just a filter condition, which has no relationship with the definition of level.

Count Nodes

IoTDB is able to use COUNT NODES <Path> LEVEL=<INTEGER> to count the number of nodes at the given level in current Metadata Tree. This could be used to query the number of devices. The usage are as follows:

  1. IoTDB > COUNT NODES root LEVEL=2
  2. IoTDB > COUNT NODES root.ln LEVEL=2
  3. IoTDB > COUNT NODES root.ln.wf01 LEVEL=3

As for the above mentioned example and Metadata tree, you can get following results:

DDL (Data Definition Language) - 图8

Note: The path of timeseries is just a filter condition, which has no relationship with the definition of level.

Delete Timeseries

To delete the timeseries we created before, we are able to use DELETE TimeSeries <PrefixPath> statement.

The usage are as follows:

  1. IoTDB> delete timeseries root.ln.wf01.wt01.status
  2. IoTDB> delete timeseries root.ln.wf01.wt01.temperature, root.ln.wf02.wt02.hardware
  3. IoTDB> delete timeseries root.ln.wf02.*

Show Devices

Similar to Show Timeseries, IoTDB also supports two ways of viewing devices:

  • SHOW DEVICES statement presents all devices information, which is equal to SHOW DEVICES root.
  • SHOW DEVICES <PrefixPath> statement specifies the PrefixPath and returns the devices information under the given level.

SQL statement is as follows:

  1. IoTDB> show devices
  2. IoTDB> show devices root.ln

TTL

IoTDB supports storage-level TTL settings, which means it is able to delete old data automatically and periodically. The benefit of using TTL is that hopefully you can control the total disk space usage and prevent the machine from running out of disks. Moreover, the query performance may downgrade as the total number of files goes up and the memory usage also increase as there are more files. Timely removing such files helps to keep at a high query performance level and reduce memory usage.

Set TTL

The SQL Statement for setting TTL is as follow:

  1. IoTDB> set ttl to root.ln 3600000

This example means that for data in root.ln, only that of the latest 1 hour will remain, the older one is removed or made invisible.

Unset TTL

To unset TTL, we can use follwing SQL statement:

  1. IoTDB> unset ttl to root.ln

After unset TTL, all data will be accepted in root.ln

FLUSH

Persist all the data points in the memory table of the storage group to the disk, and seal the data file.

  1. IoTDB> FLUSH
  2. IoTDB> FLUSH root.ln
  3. IoTDB> FLUSH root.sg1,root.sg2

MERGE

Merge sequence and unsequence data. Currently IoTDB supports the following two types of SQL to manually trigger the merge process of data files:

  • MERGE Only rewrite overlapped Chunks, the merge speed is quick, while there will be redundant data on the disk eventually.
  • FULL MERGE Rewrite all data in overlapped files, the merge speed is slow, but there will be no redundant data on the disk eventually.
  1. IoTDB> MERGE
  2. IoTDB> FULL MERGE

CLEAR CACHE

Clear the cache of chunk, chunk metadata and timeseries metadata to release the memory footprint.

  1. IoTDB> CLEAR CACHE