Key-Value Pair

The key/value of an attribute can be constant(including string) and identifier.

Below are usage scenarios of key-value pair:

  • Attributes fields of trigger. See the attributes after With clause in the example below:
  1. # 以字符串形式表示键值对
  2. CREATE TRIGGER `alert-listener-sg1d1s1`
  3. AFTER INSERT
  4. ON root.sg1.d1.s1
  5. AS 'org.apache.iotdb.db.engine.trigger.example.AlertListener'
  6. WITH (
  7. 'lo' = '0',
  8. 'hi' = '100.0'
  9. )
  10. # 以标识符和常量形式表示键值对
  11. CREATE TRIGGER `alert-listener-sg1d1s1`
  12. AFTER INSERT
  13. ON root.sg1.d1.s1
  14. AS 'org.apache.iotdb.db.engine.trigger.example.AlertListener'
  15. WITH (
  16. lo = 0,
  17. hi = 100.0
  18. )
  • Key-value pair to represent tag/attributes in timeseries:
  1. # create timeseries using string as key/value
  2. CREATE timeseries root.turbine.d1.s1(temprature)
  3. WITH datatype = FLOAT, encoding = RLE, compression = SNAPPY, 'max_point_number' = '5'
  4. TAGS('tag1' = 'v1', 'tag2'= 'v2') ATTRIBUTES('attr1' = 'v1', 'attr2' = 'v2')
  5. # create timeseries using constant as key/value
  6. CREATE timeseries root.turbine.d1.s1(temprature)
  7. WITH datatype = FLOAT, encoding = RLE, compression = SNAPPY, max_point_number = 5
  8. TAGS(tag1 = v1, tag2 = v2) ATTRIBUTES(attr1 = v1, attr2 = v2)
  1. # alter tags and attributes of timeseries
  2. ALTER timeseries root.turbine.d1.s1 SET 'newTag1' = 'newV1', 'attr1' = 'newV1'
  3. ALTER timeseries root.turbine.d1.s1 SET newTag1 = newV1, attr1 = newV1
  1. # rename tag
  2. ALTER timeseries root.turbine.d1.s1 RENAME 'tag1' TO 'newTag1'
  3. ALTER timeseries root.turbine.d1.s1 RENAME tag1 TO newTag1
  1. # upsert alias, tags, attributes
  2. ALTER timeseries root.turbine.d1.s1 UPSERT
  3. ALIAS='newAlias' TAGS('tag2' = 'newV2', 'tag3' = 'v3') ATTRIBUTES('attr3' ='v3', 'attr4'='v4')
  4. ALTER timeseries root.turbine.d1.s1 UPSERT
  5. ALIAS = newAlias TAGS(tag2 = newV2, tag3 = v3) ATTRIBUTES(attr3 = v3, attr4 = v4)
  1. # add new tags
  2. ALTER timeseries root.turbine.d1.s1 ADD TAGS 'tag3' = 'v3', 'tag4' = 'v4'
  3. ALTER timeseries root.turbine.d1.s1 ADD TAGS tag3 = v3, tag4 = v4
  1. # add new attributes
  2. ALTER timeseries root.turbine.d1.s1 ADD ATTRIBUTES 'attr3' = 'v3', 'attr4' = 'v4'
  3. ALTER timeseries root.turbine.d1.s1 ADD ATTRIBUTES attr3 = v3, attr4 = v4
  1. # query for timeseries
  2. SHOW timeseries root.ln.** WHRER 'unit' = 'c'
  3. SHOW timeseries root.ln.** WHRER unit = c
  • Attributes fields of Pipe and PipeSink.
  1. # PipeSink example
  2. CREATE PIPESINK my_iotdb AS IoTDB ('ip' = '输入你的IP')
  3. # Pipe example
  4. CREATE PIPE my_pipe TO my_iotdb FROM
  5. (select ** from root WHERE time>=yyyy-mm-dd HH:MM:SS) WITH 'SyncDelOp' = 'true'