附录2: SQL 参考文档

显示版本号

  1. show version
  1. +---------------+
  2. | version|
  3. +---------------+
  4. |0.12.0-SNAPSHOT|
  5. +---------------+
  6. Total line number = 1
  7. It costs 0.417s

Schema语句

  • 设置存储组
  1. SET STORAGE GROUP TO <FullPath>
  2. Eg: IoTDB > SET STORAGE GROUP TO root.ln.wf01.wt01
  3. Note: FullPath can not include `*`
  • 删除存储组
  1. DELETE STORAGE GROUP <FullPath> [COMMA <FullPath>]*
  2. Eg: IoTDB > DELETE STORAGE GROUP root.ln.wf01.wt01
  3. Eg: IoTDB > DELETE STORAGE GROUP root.ln.wf01.wt01, root.ln.wf01.wt02
  4. Eg: IoTDB > DELETE STORAGE GROUP root.ln.wf01.*
  5. Eg: IoTDB > DELETE STORAGE GROUP root.*
  • 创建时间序列语句
  1. CREATE TIMESERIES <FullPath> WITH <AttributeClauses>
  2. alias
  3. : LR_BRACKET ID RR_BRACKET
  4. ;
  5. attributeClauses
  6. : DATATYPE OPERATOR_EQ dataType COMMA ENCODING OPERATOR_EQ encoding
  7. (COMMA (COMPRESSOR | COMPRESSION) OPERATOR_EQ compressor=propertyValue)?
  8. (COMMA property)*
  9. tagClause
  10. attributeClause
  11. ;
  12. attributeClause
  13. : (ATTRIBUTES LR_BRACKET property (COMMA property)* RR_BRACKET)?
  14. ;
  15. tagClause
  16. : (TAGS LR_BRACKET property (COMMA property)* RR_BRACKET)?
  17. ;
  18. DataTypeValue: BOOLEAN | DOUBLE | FLOAT | INT32 | INT64 | TEXT
  19. EncodingValue: GORILLA | PLAIN | RLE | TS_2DIFF | REGULAR
  20. CompressorValue: UNCOMPRESSED | SNAPPY
  21. propertyValue: SDT | COMPDEV | COMPMINTIME | COMPMAXTIME
  22. Eg: CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN
  23. Eg: CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE
  24. Eg: CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE, COMPRESSOR=SNAPPY, MAX_POINT_NUMBER=3
  25. Eg: create timeseries root.turbine.d0.s0(temperature) with datatype=FLOAT, encoding=RLE, compression=SNAPPY tags(unit=f, description='turbine this is a test1') attributes(H_Alarm=100, M_Alarm=50)
  26. Eg: CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE, LOSS=SDT, COMPDEV=0.01
  27. Eg: CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE, LOSS=SDT, COMPDEV=0.01, COMPMINTIME=3
  28. Eg: CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE, LOSS=SDT, COMPDEV=0.01, COMPMINTIME=2, COMPMAXTIME=15
  29. Note: Datatype and encoding type must be corresponding. Please check Chapter 3 Encoding Section for details.
  30. Note: When propertyValue is SDT, it is required to set compression deviation COMPDEV, which is the maximum absolute difference between values.
  31. Note: For SDT, values withtin COMPDEV will be discarded.
  32. Note: For SDT, it is optional to set compression minimum COMPMINTIME, which is the minimum time difference between stored values for purpose of noise reduction.
  33. Note: For SDT, it is optional to set compression maximum COMPMAXTIME, which is the maximum time difference between stored values regardless of COMPDEV.
  • 删除时间序列语句
  1. DELETE TIMESERIES <PrefixPath> [COMMA <PrefixPath>]*
  2. Eg: IoTDB > DELETE TIMESERIES root.ln.wf01.wt01.status
  3. Eg: IoTDB > DELETE TIMESERIES root.ln.wf01.wt01.status, root.ln.wf01.wt01.temperature
  4. Eg: IoTDB > DELETE TIMESERIES root.ln.wf01.wt01.*
  • 修改时间序列标签属性语句
  1. ALTER TIMESERIES fullPath alterClause
  2. alterClause
  3. : RENAME beforeName=ID TO currentName=ID
  4. | SET property (COMMA property)*
  5. | DROP ID (COMMA ID)*
  6. | ADD TAGS property (COMMA property)*
  7. | ADD ATTRIBUTES property (COMMA property)*
  8. | UPSERT tagClause attributeClause
  9. ;
  10. attributeClause
  11. : (ATTRIBUTES LR_BRACKET property (COMMA property)* RR_BRACKET)?
  12. ;
  13. tagClause
  14. : (TAGS LR_BRACKET property (COMMA property)* RR_BRACKET)?
  15. ;
  16. Eg: ALTER timeseries root.turbine.d1.s1 RENAME tag1 TO newTag1
  17. Eg: ALTER timeseries root.turbine.d1.s1 SET tag1=newV1, attr1=newV1
  18. Eg: ALTER timeseries root.turbine.d1.s1 DROP tag1, tag2
  19. Eg: ALTER timeseries root.turbine.d1.s1 ADD TAGS tag3=v3, tag4=v4
  20. Eg: ALTER timeseries root.turbine.d1.s1 ADD ATTRIBUTES attr3=v3, attr4=v4
  21. EG: ALTER timeseries root.turbine.d1.s1 UPSERT TAGS(tag2=newV2, tag3=v3) ATTRIBUTES(attr3=v3, attr4=v4)
  • 显示所有时间序列语句
  1. SHOW TIMESERIES
  2. Eg: IoTDB > SHOW TIMESERIES
  3. Note: This statement can only be used in IoTDB Client. If you need to show all timeseries in JDBC, please use `DataBaseMetadata` interface.
  • 显示特定时间序列语句
  1. SHOW TIMESERIES <Path>
  2. Eg: IoTDB > SHOW TIMESERIES root
  3. Eg: IoTDB > SHOW TIMESERIES root.ln
  4. Eg: IoTDB > SHOW TIMESERIES root.ln.*.*.status
  5. Eg: IoTDB > SHOW TIMESERIES root.ln.wf01.wt01.status
  6. Note: The path can be prefix path, star path or timeseries path
  7. Note: This statement can be used in IoTDB Client and JDBC.
  • 显示满足条件的时间序列语句
  1. SHOW TIMESERIES prefixPath? showWhereClause?
  2. showWhereClause
  3. : WHERE (property | containsExpression)
  4. ;
  5. containsExpression
  6. : name=ID OPERATOR_CONTAINS value=propertyValue
  7. ;
  8. Eg: show timeseries root.ln where unit='c'
  9. Eg: show timeseries root.ln where description contains 'test1'
  • 分页显示满足条件的时间序列语句
  1. SHOW TIMESERIES prefixPath? showWhereClause? limitClause?
  2. showWhereClause
  3. : WHERE (property | containsExpression)
  4. ;
  5. containsExpression
  6. : name=ID OPERATOR_CONTAINS value=propertyValue
  7. ;
  8. limitClause
  9. : LIMIT INT offsetClause?
  10. | offsetClause? LIMIT INT
  11. ;
  12. Eg: show timeseries root.ln where unit='c'
  13. Eg: show timeseries root.ln where description contains 'test1'
  14. Eg: show timeseries root.ln where unit='c' limit 10 offset 10
  • 显示存储组语句
  1. SHOW STORAGE GROUP
  2. Eg: IoTDB > SHOW STORAGE GROUP
  3. Note: This statement can be used in IoTDB Client and JDBC.
  • 显示特定存储组语句
  1. SHOW STORAGE GROUP <PrefixPath>
  2. Eg: IoTDB > SHOW STORAGE GROUP root.*
  3. Eg: IoTDB > SHOW STORAGE GROUP root.ln
  4. Note: The path can be prefix path or star path.
  5. Note: This statement can be used in IoTDB Client and JDBC.
  • 显示Merge状态语句
  1. SHOW MERGE
  2. Eg: IoTDB > SHOW MERGE
  3. Note: This statement can be used in IoTDB Client and JDBC.
  • 显示指定路径下时间序列数语句
  1. COUNT TIMESERIES <Path>
  2. Eg: IoTDB > COUNT TIMESERIES root
  3. Eg: IoTDB > COUNT TIMESERIES root.ln
  4. Eg: IoTDB > COUNT TIMESERIES root.ln.*.*.status
  5. Eg: IoTDB > COUNT TIMESERIES root.ln.wf01.wt01.status
  6. Note: The path can be prefix path, star path or timeseries path.
  7. Note: This statement can be used in IoTDB Client and JDBC.
  1. COUNT TIMESERIES <Path> GROUP BY LEVEL=<INTEGER>
  2. Eg: IoTDB > COUNT TIMESERIES root GROUP BY LEVEL=1
  3. Eg: IoTDB > COUNT TIMESERIES root.ln GROUP BY LEVEL=2
  4. Eg: IoTDB > COUNT TIMESERIES root.ln.wf01 GROUP BY LEVEL=3
  5. Note: The path can be prefix path or timeseries path.
  6. Note: This statement can be used in IoTDB Client and JDBC.
  • 显示指定路径下特定层级的节点数语句
  1. COUNT NODES <Path> LEVEL=<INTEGER>
  2. Eg: IoTDB > COUNT NODES root LEVEL=2
  3. Eg: IoTDB > COUNT NODES root.ln LEVEL=2
  4. Eg: IoTDB > COUNT NODES root.ln.* LEVEL=3
  5. Eg: IoTDB > COUNT NODES root.ln.wf01 LEVEL=3
  6. Note: The path can be prefix path or timeseries path.
  7. Note: This statement can be used in IoTDB Client and JDBC.
  • 显示所有设备语句
  1. SHOW DEVICES (WITH STORAGE GROUP)? limitClause?
  2. Eg: IoTDB > SHOW DEVICES
  3. Eg: IoTDB > SHOW DEVICES WITH STORAGE GROUP
  4. Note: This statement can be used in IoTDB Client and JDBC.
  • 显示特定设备语句
  1. SHOW DEVICES <PrefixPath> (WITH STORAGE GROUP)? limitClause?
  2. Eg: IoTDB > SHOW DEVICES root
  3. Eg: IoTDB > SHOW DEVICES root.ln
  4. Eg: IoTDB > SHOW DEVICES root.*.wf01
  5. Eg: IoTDB > SHOW DEVICES root.ln WITH STORAGE GROUP
  6. Eg: IoTDB > SHOW DEVICES root.*.wf01 WITH STORAGE GROUP
  7. Note: The path can be prefix path or star path.
  8. Note: This statement can be used in IoTDB Client and JDBC.
  • 显示ROOT节点的子节点名称语句
  1. SHOW CHILD PATHS
  2. Eg: IoTDB > SHOW CHILD PATHS
  3. Note: This statement can be used in IoTDB Client and JDBC.
  • 显示子节点名称语句
  1. SHOW CHILD PATHS <Path>
  2. Eg: IoTDB > SHOW CHILD PATHS root
  3. Eg: IoTDB > SHOW CHILD PATHS root.ln
  4. Eg: IoTDB > SHOW CHILD PATHS root.*.wf01
  5. Eg: IoTDB > SHOW CHILD PATHS root.ln.wf*
  6. Note: The path can be prefix path or star path, the nodes can be in a "prefix + star" format.
  7. Note: This statement can be used in IoTDB Client and JDBC.
  • 为 schema 创建快照
  1. CREATE SNAPSHOT FOR SCHEMA

数据管理语句

  • 插入记录语句
  1. INSERT INTO <PrefixPath> LPAREN TIMESTAMP COMMA <Sensor> [COMMA <Sensor>]* RPAREN VALUES LPAREN <TimeValue>, <PointValue> [COMMA <PointValue>]* RPAREN
  2. Sensor : Identifier
  3. Eg: IoTDB > INSERT INTO root.ln.wf01.wt01(timestamp,status) values(1509465600000,true)
  4. Eg: IoTDB > INSERT INTO root.ln.wf01.wt01(timestamp,status) VALUES(NOW(), false)
  5. Eg: IoTDB > INSERT INTO root.ln.wf01.wt01(timestamp,temperature) VALUES(2017-11-01T00:17:00.000+08:00,24.22028)
  6. Eg: IoTDB > INSERT INTO root.ln.wf01.wt01(timestamp, status, temperature) VALUES (1509466680000, false, 20.060787);
  7. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  8. Note: The order of Sensor and PointValue need one-to-one correspondence
  • 删除记录语句
  1. DELETE FROM <PrefixPath> [COMMA <PrefixPath>]* [WHERE <WhereClause>]?
  2. WhereClause : <Condition> [(AND) <Condition>]*
  3. Condition : <TimeExpr> [(AND) <TimeExpr>]*
  4. TimeExpr : TIME PrecedenceEqualOperator (<TimeValue> | <RelativeTime>)
  5. Eg: DELETE FROM root.ln.wf01.wt01.temperature WHERE time > 2016-01-05T00:15:00+08:00 and time < 2017-11-1T00:05:00+08:00
  6. Eg: DELETE FROM root.ln.wf01.wt01.status, root.ln.wf01.wt01.temperature WHERE time < NOW()
  7. Eg: DELETE FROM root.ln.wf01.wt01.* WHERE time >= 1509466140000
  • 选择记录语句
  1. SELECT <SelectClause> FROM <FromClause> [WHERE <WhereClause>]?
  2. SelectClause : <SelectPath> (COMMA <SelectPath>)*
  3. SelectPath : <FUNCTION> LPAREN <Path> RPAREN | <Path>
  4. FUNCTION : COUNT , MIN_TIME’, MAX_TIME’, MIN_VALUE’, MAX_VALUE
  5. FromClause : <PrefixPath> (COMMA <PrefixPath>)?
  6. WhereClause : <Condition> [(AND | OR) <Condition>]*
  7. Condition : <Expression> [(AND | OR) <Expression>]*
  8. Expression : [NOT | !]? <TimeExpr> | [NOT | !]? <SensorExpr>
  9. TimeExpr : TIME PrecedenceEqualOperator (<TimeValue> | <RelativeTime>)
  10. RelativeTimeDurationUnit = Integer ('Y'|'MO'|'W'|'D'|'H'|'M'|'S'|'MS'|'US'|'NS')
  11. RelativeTime : (now() | <TimeValue>) [(+|-) RelativeTimeDurationUnit]+
  12. SensorExpr : (<Timeseries> | <Path>) PrecedenceEqualOperator <PointValue>
  13. Eg: IoTDB > SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < 24 and time > 2017-11-1 0:13:00
  14. Eg. IoTDB > SELECT * FROM root
  15. Eg. IoTDB > SELECT * FROM root where time > now() - 5m
  16. Eg. IoTDB > SELECT * FROM root.ln.*.wf*
  17. Eg. IoTDB > SELECT COUNT(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 25
  18. Eg. IoTDB > SELECT MIN_TIME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 25
  19. Eg. IoTDB > SELECT MAX_TIME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature > 24
  20. Eg. IoTDB > SELECT MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature > 23
  21. Eg. IoTDB > SELECT MAX_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 25
  22. Eg. IoTDB > SELECT COUNT(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 25 GROUP BY LEVEL=1
  23. Note: the statement needs to satisfy this constraint: <Path>(SelectClause) + <PrefixPath>(FromClause) = <Timeseries>
  24. Note: If the <SensorExpr>(WhereClause) is started with <Path> and not with ROOT, the statement needs to satisfy this constraint: <PrefixPath>(FromClause) + <Path>(SensorExpr) = <Timeseries>
  25. Note: In Version 0.7.0, if <WhereClause> includes `OR`, time filter can not be used.
  26. Note: There must be a space on both sides of the plus and minus operator appearing in the time expression
  • Group By 语句
  1. SELECT <SelectClause> FROM <FromClause> WHERE <WhereClause> GROUP BY <GroupByTimeClause>
  2. SelectClause : <Function> [COMMA < Function >]*
  3. Function : <AggregationFunction> LPAREN <Path> RPAREN
  4. FromClause : <PrefixPath>
  5. WhereClause : <Condition> [(AND | OR) <Condition>]*
  6. Condition : <Expression> [(AND | OR) <Expression>]*
  7. Expression : [NOT | !]? <TimeExpr> | [NOT | !]? <SensorExpr>
  8. TimeExpr : TIME PrecedenceEqualOperator (<TimeValue> | <RelativeTime>)
  9. RelativeTimeDurationUnit = Integer ('Y'|'MO'|'W'|'D'|'H'|'M'|'S'|'MS'|'US'|'NS')
  10. RelativeTime : (now() | <TimeValue>) [(+|-) RelativeTimeDurationUnit]+
  11. SensorExpr : (<Timeseries> | <Path>) PrecedenceEqualOperator <PointValue>
  12. GroupByTimeClause : LPAREN <TimeInterval> COMMA <TimeUnit> (COMMA <TimeUnit>)? RPAREN
  13. TimeInterval: LSBRACKET <TimeValue> COMMA <TimeValue> RRBRACKET | LRBRACKET <TimeValue> COMMA <TimeValue> RSBRACKET
  14. TimeUnit : Integer <DurationUnit>
  15. DurationUnit : "ms" | "s" | "m" | "h" | "d" | "w" | "mo"
  16. Eg: SELECT COUNT(status), COUNT(temperature) FROM root.ln.wf01.wt01 where temperature < 24 GROUP BY([1509465720000, 1509466380000), 5m)
  17. Eg: SELECT COUNT(status), COUNT(temperature) FROM root.ln.wf01.wt01 where temperature < 24 GROUP BY((1509465720000, 1509466380000], 5m)
  18. Eg. SELECT COUNT (status), MAX_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE time < 1509466500000 GROUP BY([1509465720000, 1509466380000), 5m, 10m)
  19. Eg. SELECT MIN_TIME(status), MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE temperature < 25 GROUP BY ([1509466140000, 1509466380000), 3m, 5ms)
  20. Eg. SELECT MIN_TIME(status), MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE temperature < 25 GROUP BY ((1509466140000, 1509466380000], 3m, 5ms)
  21. Eg. SELECT MIN_TIME(status), MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE temperature < 25 GROUP BY ((1509466140000, 1509466380000], 1mo)
  22. Eg. SELECT MIN_TIME(status), MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE temperature < 25 GROUP BY ((1509466140000, 1509466380000], 1mo, 1mo)
  23. Eg. SELECT MIN_TIME(status), MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE temperature < 25 GROUP BY ((1509466140000, 1509466380000], 1mo, 2mo)
  24. Note: the statement needs to satisfy this constraint: <Path>(SelectClause) + <PrefixPath>(FromClause) = <Timeseries>
  25. Note: If the <SensorExpr>(WhereClause) is started with <Path> and not with ROOT, the statement needs to satisfy this constraint: <PrefixPath>(FromClause) + <Path>(SensorExpr) = <Timeseries>
  26. Note: <TimeValue>(TimeInterval) needs to be greater than 0
  27. Note: First <TimeValue>(TimeInterval) in needs to be smaller than second <TimeValue>(TimeInterval)
  28. Note: <TimeUnit> needs to be greater than 0
  29. Note: Third <TimeUnit> if set shouldn't be smaller than second <TimeUnit>
  30. Note: If the second <DurationUnit> is "mo", the third <DurationUnit> need to be in month
  31. Note: If the third <DurationUnit> is "mo", the second <DurationUnit> can be in any unit
  • Fill 语句
  1. SELECT <SelectClause> FROM <FromClause> WHERE <WhereClause> FILL <FillClause>
  2. SelectClause : <Path> [COMMA <Path>]*
  3. FromClause : < PrefixPath > [COMMA < PrefixPath >]*
  4. WhereClause : <WhereExpression>
  5. WhereExpression : TIME EQUAL <TimeValue>
  6. FillClause : LPAREN <TypeClause> [COMMA <TypeClause>]* RPAREN
  7. TypeClause : <Int32Clause> | <Int64Clause> | <FloatClause> | <DoubleClause> | <BoolClause> | <TextClause>
  8. Int32Clause: INT32 LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
  9. Int64Clause: INT64 LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
  10. FloatClause: FLOAT LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
  11. DoubleClause: DOUBLE LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
  12. BoolClause: BOOLEAN LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
  13. TextClause: TEXT LBRACKET (<LinearClause> | <PreviousClause>) RBRACKET
  14. PreviousClause : PREVIOUS [COMMA <ValidPreviousTime>]?
  15. LinearClause : LINEAR [COMMA <ValidPreviousTime> COMMA <ValidBehindTime>]?
  16. ValidPreviousTime, ValidBehindTime: <TimeUnit>
  17. TimeUnit : Integer <DurationUnit>
  18. DurationUnit : "ms" | "s" | "m" | "h" | "d" | "w"
  19. Eg: SELECT temperature FROM root.ln.wf01.wt01 WHERE time = 2017-11-01T16:37:50.000 FILL(float[previous, 1m])
  20. Eg: SELECT temperature,status FROM root.ln.wf01.wt01 WHERE time = 2017-11-01T16:37:50.000 FILL (float[linear, 1m, 1m], boolean[previous, 1m])
  21. Eg: SELECT temperature,status,hardware FROM root.ln.wf01.wt01 WHERE time = 2017-11-01T16:37:50.000 FILL (float[linear, 1m, 1m], boolean[previous, 1m], text[previous])
  22. Eg: SELECT temperature,status,hardware FROM root.ln.wf01.wt01 WHERE time = 2017-11-01T16:37:50.000 FILL (float[linear], boolean[previous, 1m], text[previous])
  23. Note: the statement needs to satisfy this constraint: <PrefixPath>(FromClause) + <Path>(SelectClause) = <Timeseries>
  24. Note: Integer in <TimeUnit> needs to be greater than 0
  • Group By Fill语句
  1. SELECT <SelectClause> FROM <FromClause> WHERE <WhereClause> GROUP BY <GroupByClause> (FILL <GROUPBYFillClause>)?
  2. GroupByClause : LPAREN <TimeInterval> COMMA <TimeUnit> RPAREN
  3. GROUPBYFillClause : LPAREN <TypeClause> RPAREN
  4. TypeClause : <AllClause> | <Int32Clause> | <Int64Clause> | <FloatClause> | <DoubleClause> | <BoolClause> | <TextClause>
  5. AllClause: ALL LBRACKET (<PreviousUntilLastClause> | <PreviousClause>) RBRACKET
  6. Int32Clause: INT32 LBRACKET (<PreviousUntilLastClause> | <PreviousClause>) RBRACKET
  7. Int64Clause: INT64 LBRACKET (<PreviousUntilLastClause> | <PreviousClause>) RBRACKET
  8. FloatClause: FLOAT LBRACKET (<PreviousUntilLastClause> | <PreviousClause>) RBRACKET
  9. DoubleClause: DOUBLE LBRACKET (<PreviousUntilLastClause> | <PreviousClause>) RBRACKET
  10. BoolClause: BOOLEAN LBRACKET (<PreviousUntilLastClause> | <PreviousClause>) RBRACKET
  11. TextClause: TEXT LBRACKET (<PreviousUntilLastClause> | <PreviousClause>) RBRACKET
  12. PreviousClause : PREVIOUS
  13. PreviousUntilLastClause : PREVIOUSUNTILLAST
  14. Eg: SELECT last_value(temperature) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (float[PREVIOUS])
  15. Eg: SELECT last_value(temperature) FROM root.ln.wf01.wt01 GROUP BY((15, 100], 5m) FILL (float[PREVIOUS])
  16. Eg: SELECT last_value(power) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (int32[PREVIOUSUNTILLAST])
  17. Eg: SELECT last_value(power) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (int32[PREVIOUSUNTILLAST, 5m])
  18. Eg: SELECT last_value(temperature), last_value(power) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (ALL[PREVIOUS])
  19. Eg: SELECT last_value(temperature), last_value(power) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (ALL[PREVIOUS, 5m])
  20. Note: In group by fill, sliding step is not supported in group by clause
  21. Note: Now, only last_value aggregation function is supported in group by fill.
  22. Note: Linear fill is not supported in group by fill.
  • Order by time 语句
  1. SELECT <SelectClause> FROM <FromClause> WHERE <WhereClause> GROUP BY <GroupByClause> (FILL <GROUPBYFillClause>)? orderByTimeClause?
  2. orderByTimeClause: order by time (asc | desc)?
  3. Eg: SELECT last_value(temperature) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (float[PREVIOUS]) order by time desc
  4. Eg: SELECT * from root order by time desc
  5. Eg: SELECT * from root order by time desc align by device
  6. Eg: SELECT * from root order by time desc disable align
  7. Eg: SELECT last * from root order by time desc
  • Limit & SLimit 语句
  1. SELECT <SelectClause> FROM <FromClause> [WHERE <WhereClause>] [<LIMITClause>] [<SLIMITClause>]
  2. SelectClause : [<Path> | Function]+
  3. Function : <AggregationFunction> LPAREN <Path> RPAREN
  4. FromClause : <Path>
  5. WhereClause : <Condition> [(AND | OR) <Condition>]*
  6. Condition : <Expression> [(AND | OR) <Expression>]*
  7. Expression: [NOT|!]?<TimeExpr> | [NOT|!]?<SensorExpr>
  8. TimeExpr : TIME PrecedenceEqualOperator (<TimeValue> | <RelativeTime>)
  9. RelativeTimeDurationUnit = Integer ('Y'|'MO'|'W'|'D'|'H'|'M'|'S'|'MS'|'US'|'NS')
  10. RelativeTime : (now() | <TimeValue>) [(+|-) RelativeTimeDurationUnit]+
  11. SensorExpr : (<Timeseries>|<Path>) PrecedenceEqualOperator <PointValue>
  12. LIMITClause : LIMIT <N> [OFFSETClause]?
  13. N : Integer
  14. OFFSETClause : OFFSET <OFFSETValue>
  15. OFFSETValue : Integer
  16. SLIMITClause : SLIMIT <SN> [SOFFSETClause]?
  17. SN : Integer
  18. SOFFSETClause : SOFFSET <SOFFSETValue>
  19. SOFFSETValue : Integer
  20. Eg: IoTDB > SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < 24 and time > 2017-11-1 0:13:00 LIMIT 3 OFFSET 2
  21. Eg. IoTDB > SELECT COUNT (status), MAX_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE time < 1509466500000 GROUP BY([1509465720000, 1509466380000], 5m) LIMIT 3
  22. Note: N, OFFSETValue, SN and SOFFSETValue must be greater than 0.
  23. Note: The order of <LIMITClause> and <SLIMITClause> does not affect the grammatical correctness.
  24. Note: <FillClause> can not use <LIMITClause> but not <SLIMITClause>.
  • Align by device语句
  1. AlignbyDeviceClause : ALIGN BY DEVICE
  2. 规则:
  3. 1. 大小写不敏感.
  4. 正例: select * from root.sg1 align by device
  5. 正例: select * from root.sg1 ALIGN BY DEVICE
  6. 2. AlignbyDeviceClause 只能放在末尾.
  7. 正例: select * from root.sg1 where time > 10 align by device
  8. 错例: select * from root.sg1 align by device where time > 10
  9. 3. Select子句中的path只能是单层,或者通配符,不允许有path分隔符"."
  10. 正例: select s0,s1 from root.sg1.* align by device
  11. 正例: select s0,s1 from root.sg1.d0, root.sg1.d1 align by device
  12. 正例: select * from root.sg1.* align by device
  13. 正例: select * from root align by device
  14. 正例: select s0,s1,* from root.*.* align by device
  15. 错例: select d0.s1, d0.s2, d1.s0 from root.sg1 align by device
  16. 错例: select *.s0, *.s1 from root.* align by device
  17. 错例: select *.*.* from root align by device
  18. 4.相同measurement的各设备的数据类型必须都相同,
  19. 正例: select s0 from root.sg1.d0,root.sg1.d1 align by device
  20. root.sg1.d0.s0 and root.sg1.d1.s0 are both INT32.
  21. 正例: select count(s0) from root.sg1.d0,root.sg1.d1 align by device
  22. count(root.sg1.d0.s0) and count(root.sg1.d1.s0) are both INT64.
  23. 错例: select s0 from root.sg1.d0, root.sg2.d3 align by device
  24. root.sg1.d0.s0 is INT32 while root.sg2.d3.s0 is FLOAT.
  25. 5. 结果集的展示规则:对于select中给出的列,不论是否有数据(是否被注册),均会被显示。此外,select子句中还支持常数列(例如,'a', '123'等等)。
  26. 例如, "select s0,s1,s2,'abc',s1,s2 from root.sg.d0, root.sg.d1, root.sg.d2 align by device". 假设只有下述三列有数据:
  27. - root.sg.d0.s0
  28. - root.sg.d0.s1
  29. - root.sg.d1.s0
  30. 结果集形如:
  31. | Time | Device | s0 | s1 | s2 | 'abc' | s1 | s2 |
  32. | --- | --- | ---| ---| null | 'abc' | ---| null |
  33. | 1 |root.sg.d0| 20 | 2.5| null | 'abc' | 2.5| null |
  34. | 2 |root.sg.d0| 23 | 3.1| null | 'abc' | 3.1| null |
  35. | ... | ... | ...| ...| null | 'abc' | ...| null |
  36. | 1 |root.sg.d1| 12 |null| null | 'abc' |null| null |
  37. | 2 |root.sg.d1| 19 |null| null | 'abc' |null| null |
  38. | ... | ... | ...| ...| null | 'abc' | ...| null |
  39. 注意注意 设备'root.sg.d1''s0'的值全为null
  40. 6. From中重复写设备名字或者设备前缀是没有任何作用的。
  41. 例如, "select s0,s1 from root.sg.d0,root.sg.d0,root.sg.d1 align by device" 等于 "select s0,s1 from root.sg.d0,root.sg.d1 align by device".
  42. 例如. "select s0,s1 from root.sg.*,root.sg.d0 align by device" 等于 "select s0,s1 from root.sg.* align by device".
  43. 7. Select子句中重复写列名是生效的。例如, "select s0,s0,s1 from root.sg.* align by device" 不等于 "select s0,s1 from root.sg.* align by device".
  44. 8. Where子句中时间过滤条件和值过滤条件均可以使用,值过滤条件可以使用叶子节点 path,或以 root 开头的整个 path,不允许存在通配符。例如,
  45. - select * from root.sg.* where time = 1 align by device
  46. - select * from root.sg.* where s0 < 100 align by device
  47. - select * from root.sg.* where time < 20 AND s0 > 50 align by device
  48. - select * from root.sg.d0 where root.sg.d0.s0 = 15 align by device
  49. 9. 更多正例:
  50. - select * from root.vehicle align by device
  51. - select s0,s0,s1 from root.vehicle.* align by device
  52. - select s0,s1 from root.vehicle.* limit 10 offset 1 align by device
  53. - select * from root.vehicle slimit 10 soffset 2 align by device
  54. - select * from root.vehicle where time > 10 align by device
  55. - select * from root.vehicle.* where time < 10 AND s0 > 25 align by device
  56. - select * from root.vehicle where root.vehicle.d0.s0>0 align by device
  57. - select count(*) from root.vehicle align by device
  58. - select sum(*) from root.vehicle GROUP BY (20ms,0,[2,50]) align by device
  59. - select * from root.vehicle where time = 3 Fill(int32[previous, 5ms]) align by device
  • Disable align 语句
  1. 规则:
  2. 1. 大小写均可.
  3. 正例: select * from root.sg1 disable align
  4. 正例: select * from root.sg1 DISABLE ALIGN
  5. 2. Disable Align只能用于查询语句句尾.
  6. 正例: select * from root.sg1 where time > 10 disable align
  7. 错例: select * from root.sg1 disable align where time > 10
  8. 3. Disable Align 不能用于聚合查询、Fill语句、Group byGroup by device语句,但可用于Limit语句。
  9. 正例: select * from root.sg1 limit 3 offset 2 disable align
  10. 正例: select * from root.sg1 slimit 3 soffset 2 disable align
  11. 错例: select count(s0),count(s1) from root.sg1.d1 disable align
  12. 错例: select * from root.vehicle where root.vehicle.d0.s0>0 disable align
  13. 错例: select * from root.vehicle align by device disable align
  14. 4. 结果显示若无数据显示为空白.
  15. 查询结果样式如下表:
  16. | Time | root.sg.d0.s1 | Time | root.sg.d0.s2 | Time | root.sg.d1.s1 |
  17. | --- | --- | --- | --- | --- | --- |
  18. | 1 | 100 | 20 | 300 | 400 | 600 |
  19. | 2 | 300 | 40 | 800 | 700 | 900 |
  20. | 4 | 500 | | | 800 | 1000 |
  21. | | | | | 900 | 8000 |
  22. 5. 一些正确使用样例:
  23. - select * from root.vehicle disable align
  24. - select s0,s0,s1 from root.vehicle.* disable align
  25. - select s0,s1 from root.vehicle.* limit 10 offset 1 disable align
  26. - select * from root.vehicle slimit 10 soffset 2 disable align
  27. - select * from root.vehicle where time > 10 disable align
  • Last语句

Last 语句返回所要查询时间序列的最近时间戳的一条数据

  1. SELECT LAST <SelectClause> FROM <FromClause> WHERE <WhereClause>
  2. Select Clause : <Path> [COMMA <Path>]*
  3. FromClause : < PrefixPath > [COMMA < PrefixPath >]*
  4. WhereClause : <TimeExpr> [(AND | OR) <TimeExpr>]*
  5. TimeExpr : TIME PrecedenceEqualOperator (<TimeValue> | <RelativeTime>)
  6. Eg. SELECT LAST s1 FROM root.sg.d1
  7. Eg. SELECT LAST s1, s2 FROM root.sg.d1
  8. Eg. SELECT LAST s1 FROM root.sg.d1, root.sg.d2
  9. Eg. SELECT LAST s1 FROM root.sg.d1 where time > 100
  10. Eg. SELECT LAST s1, s2 FROM root.sg.d1 where time >= 500
  11. 规则:
  12. 1. 需要满足PrefixPath.Path 为一条完整的时间序列,即 <PrefixPath> + <Path> = <Timeseries>
  13. 2. 当前SELECT LAST 语句只支持包含'>''>='的时间过滤条件
  14. 3. 结果集以四列的表格的固定形式返回。
  15. 例如 "select last s1, s2 from root.sg.d1, root.sg.d2", 结果集返回如下:
  16. | Time | Path | Value | Type |
  17. | --- | ------------ | ----- | ----- |
  18. | 5 | root.sg.d1.s1| 100 | INT32 |
  19. | 2 | root.sg.d1.s2| 400 | INT32 |
  20. | 4 | root.sg.d2.s1| 250 | INT32 |
  21. | 9 | root.sg.d2.s2| 600 | INT32 |
  22. 4. 注意LAST语句不支持与"disable align"关键词一起使用。
  • As 语句

As 语句为 SELECT 语句中出现的时间序列规定一个别名

  1. 在每个查询中都可以使用 As 语句来规定时间序列的别名,但是对于通配符的使用有一定限制。
  2. 1. 原始数据查询:
  3. select s1 as speed, s2 as temperature from root.sg.d1
  4. 结果集将显示为:
  5. | Time | speed | temperature |
  6. | ... | ... | .... |
  7. 2. 聚合查询
  8. select count(s1) as s1_num, max_value(s2) as s2_max from root.sg.d1
  9. 3. 降频聚合查询
  10. select count(s1) as s1_num from root.sg.d1 group by ([100,500), 80ms)
  11. 4. 按设备对齐查询
  12. select s1 as speed, s2 as temperature from root.sg.d1 align by device
  13. select count(s1) as s1_num, count(s2), count(s3) as s3_num from root.sg.d2 align by device
  14. 5. 最新数据查询
  15. select last s1 as speed, s2 from root.sg.d1
  16. 规则:
  17. 1. 除按设备对齐查询外,每一个 AS 语句必须唯一对应一个时间序列。
  18. E.g. select s1 as temperature from root.sg.*
  19. 此时如果存储组 root.sg.* 中含有多个设备,则会抛出异常。
  20. 2. 按设备对齐查询中,每个 AS 语句对应的前缀路径可以含多个设备,而后缀路径不能含多个传感器。
  21. E.g. select s1 as temperature from root.sg.*
  22. 这种情况即使有多个设备,也可以正常显示。
  23. E.g. select * as temperature from root.sg.d1
  24. 这种情况如果 * 匹配多个传感器,则无法正常显示。
  • Regexp 语句

Regexp语句仅支持数据类型为 TEXT的列进行过滤,传入的过滤条件为 Java 标准库风格的正则表达式

  1. SELECT <SelectClause> FROM <FromClause> WHERE <WhereClause>
  2. Select Clause : <Path> [COMMA <Path>]*
  3. FromClause : < PrefixPath > [COMMA < PrefixPath >]*
  4. WhereClause : andExpression (OPERATOR_OR andExpression)*
  5. andExpression : predicate (OPERATOR_AND predicate)*
  6. predicate : (suffixPath | fullPath) REGEXP regularExpression
  7. regularExpression: Java standard regularexpression, like '^[a-z][0-9]$', [details](https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html)
  8. Eg. select s1 from root.sg.d1 where s1 regexp '^[0-9]*$'
  9. Eg. select s1, s2 FROM root.sg.d1 where s1 regexp '^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$' and s2 regexp '^\d{15}|\d{18}$'
  10. Eg. select * from root.sg.d1 where s1 regexp '^[a-zA-Z]\w{5,17}$'
  11. Eg. select * from root.sg.d1 where s1 regexp '^\d{4}-\d{1,2}-\d{1,2}' and time > 100
  • Like 语句

Like语句的用法和mysql相同, 但是仅支持对数据类型为 TEXT的列进行过滤

  1. SELECT <SelectClause> FROM <FromClause> WHERE <WhereClause>
  2. Select Clause : <Path> [COMMA <Path>]*
  3. FromClause : < PrefixPath > [COMMA < PrefixPath >]*
  4. WhereClause : andExpression (OPERATOR_OR andExpression)*
  5. andExpression : predicate (OPERATOR_AND predicate)*
  6. predicate : (suffixPath | fullPath) LIKE likeExpression
  7. likeExpression : string that may contains "%" or "_", while "%value" means a string that ends with the value, "value%" means a string starts with the value, "%value%" means string that contains values, and "_" represents any character.
  8. Eg. select s1 from root.sg.d1 where s1 like 'abc'
  9. Eg. select s1, s2 from root.sg.d1 where s1 like 'abc%'
  10. Eg. select * from root.sg.d1 where s1 like 'abc_'
  11. Eg. select * from root.sg.d1 where s1 like 'abc\%'
  12. 这种情况,'\%'表示'%'将会被转义
  13. 结果集将显示为:
  14. | Time | Path | Value |
  15. | --- | ------------ | ----- |
  16. | 200 | root.sg.d1.s1| abc% |

数据库管理语句

  • 创建用户
  1. CREATE USER <userName> <password>;
  2. userName:=identifier
  3. password:=string
  4. Eg: IoTDB > CREATE USER thulab 'pwd';
  • 删除用户
  1. DROP USER <userName>;
  2. userName:=identifier
  3. Eg: IoTDB > DROP USER xiaoming;
  • 创建角色
  1. CREATE ROLE <roleName>;
  2. roleName:=identifie
  3. Eg: IoTDB > CREATE ROLE admin;
  • 删除角色
  1. DROP ROLE <roleName>;
  2. roleName:=identifier
  3. Eg: IoTDB > DROP ROLE admin;
  • 赋予用户权限
  1. GRANT USER <userName> PRIVILEGES <privileges> ON <nodeName>;
  2. userName:=identifier
  3. nodeName:=identifier (DOT identifier)*
  4. privileges:= string (COMMA string)*
  5. Eg: IoTDB > GRANT USER tempuser PRIVILEGES 'DELETE_TIMESERIES' on root.ln;
  • 赋予角色权限
  1. GRANT ROLE <roleName> PRIVILEGES <privileges> ON <nodeName>;
  2. privileges:= string (COMMA string)*
  3. roleName:=identifier
  4. nodeName:=identifier (DOT identifier)*
  5. Eg: IoTDB > GRANT ROLE temprole PRIVILEGES 'DELETE_TIMESERIES' ON root.ln;
  • 赋予用户角色
  1. GRANT <roleName> TO <userName>;
  2. roleName:=identifier
  3. userName:=identifier
  4. Eg: IoTDB > GRANT temprole TO tempuser;
  • 撤销用户权限
  1. REVOKE USER <userName> PRIVILEGES <privileges> ON <nodeName>;
  2. privileges:= string (COMMA string)*
  3. userName:=identifier
  4. nodeName:=identifier (DOT identifier)*
  5. Eg: IoTDB > REVOKE USER tempuser PRIVILEGES 'DELETE_TIMESERIES' on root.ln;
  • 撤销角色权限
  1. REVOKE ROLE <roleName> PRIVILEGES <privileges> ON <nodeName>;
  2. privileges:= string (COMMA string)*
  3. roleName:= identifier
  4. nodeName:=identifier (DOT identifier)*
  5. Eg: IoTDB > REVOKE ROLE temprole PRIVILEGES 'DELETE_TIMESERIES' ON root.ln;
  • 撤销用户角色
  1. REVOKE <roleName> FROM <userName>;
  2. roleName:=identifier
  3. userName:=identifier
  4. Eg: IoTDB > REVOKE temprole FROM tempuser;
  • 列出用户
  1. LIST USER
  2. Eg: IoTDB > LIST USER
  • 列出角色
  1. LIST ROLE
  2. Eg: IoTDB > LIST ROLE
  • 列出权限
  1. LIST PRIVILEGES USER <username> ON <path>;
  2. username:=identifier
  3. path=‘root (DOT identifier)*
  4. Eg: IoTDB > LIST PRIVILEGES USER sgcc_wirte_user ON root.sgcc;
  • 列出角色权限
  1. LIST ROLE PRIVILEGES <roleName>
  2. roleName:=identifier
  3. Eg: IoTDB > LIST ROLE PRIVILEGES actor;
  • 列出角色在具体路径上的权限
  1. LIST PRIVILEGES ROLE <roleName> ON <path>;
  2. roleName:=identifier
  3. path=‘root (DOT identifier)*
  4. Eg: IoTDB > LIST PRIVILEGES ROLE wirte_role ON root.sgcc;
  • 列出用户权限
  1. LIST USER PRIVILEGES <username> ;
  2. username:=identifier
  3. Eg: IoTDB > LIST USER PRIVILEGES tempuser;
  • 列出用户角色
  1. LIST ALL ROLE OF USER <username> ;
  2. username:=identifier
  3. Eg: IoTDB > LIST ALL ROLE OF USER tempuser;
  • 列出角色用户
  1. LIST ALL USER OF ROLE <roleName>;
  2. roleName:=identifier
  3. Eg: IoTDB > LIST ALL USER OF ROLE roleuser;
  • 更新密码
  1. ALTER USER <username> SET PASSWORD <password>;
  2. roleName:=identifier
  3. password:=string
  4. Eg: IoTDB > ALTER USER tempuser SET PASSWORD 'newpwd';

功能

  • COUNT
  1. SELECT COUNT(Path) (COMMA COUNT(Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT COUNT(status), COUNT(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • FIRST_VALUE 原有的 FIRST 方法在 v0.10.0 版本更名为 FIRST_VALUE
  1. SELECT FIRST_VALUE (Path) (COMMA FIRST_VALUE (Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT FIRST_VALUE (status), FIRST_VALUE (temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • LAST_VALUE
  1. SELECT LAST_VALUE (Path) (COMMA LAST_VALUE (Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT LAST_VALUE (status), LAST_VALUE (temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • MAX_TIME
  1. SELECT MAX_TIME (Path) (COMMA MAX_TIME (Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT MAX_TIME(status), MAX_TIME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • MAX_VALUE
  1. SELECT MAX_VALUE (Path) (COMMA MAX_VALUE (Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT MAX_VALUE(status), MAX_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • EXTREME 极值:具有最大绝对值的值(正值优先)
  1. SELECT EXTREME (Path) (COMMA EXTREME (Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT EXTREME(status), EXTREME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • AVG 原有的 MEAN 方法在 v0.9.0 版本更名为 AVG
  1. SELECT AVG (Path) (COMMA AVG (Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT AVG (temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • MIN_TIME
  1. SELECT MIN_TIME (Path) (COMMA MIN_TIME (Path))*FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT MIN_TIME(status), MIN_TIME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • MIN_VALUE
  1. SELECT MIN_VALUE (Path) (COMMA MIN_VALUE (Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT MIN_VALUE(status),MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
  • NOW
  1. NOW()
  2. Eg. INSERT INTO root.ln.wf01.wt01(timestamp,status) VALUES(NOW(), false)
  3. Eg. DELETE FROM root.ln.wf01.wt01.status, root.ln.wf01.wt01.temperature WHERE time < NOW()
  4. Eg. SELECT * FROM root WHERE time < NOW()
  5. Eg. SELECT COUNT(temperature) FROM root.ln.wf01.wt01 WHERE time < NOW()
  • SUM
  1. SELECT SUM(Path) (COMMA SUM(Path))* FROM <FromClause> [WHERE <WhereClause>]?
  2. Eg. SELECT SUM(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
  3. Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>

TTL

IoTDB支持对存储组级别设置数据存活时间(TTL),这使得IoTDB可以定期、自动地删除一定时间之前的数据。合理使用TTL 可以帮助您控制IoTDB占用的总磁盘空间以避免出现磁盘写满等异常。并且,随着文件数量的增多,查询性能往往随之下降, 内存占用也会有所提高。及时地删除一些较老的文件有助于使查询性能维持在一个较高的水平和减少内存资源的占用。 IoTDB中的TTL操作可以由以下的语句进行实现:

  • 设置 TTL
  1. SET TTL TO StorageGroupName TTLTime
  2. Eg. SET TTL TO root.group1 3600000
  3. 这个例子展示了如何使得root.group1这个存储组只保留近一个小时的数据,一个小时前的数据会被删除或者进入不可见状态。
  4. 注意: TTLTime 应是毫秒时间戳。一旦TTL被设置,超过TTL时间范围的写入将被拒绝。
  • 取消 TTL
  1. UNSET TTL TO StorageGroupName
  2. Eg. UNSET TTL TO root.group1
  3. 这个例子展示了如何取消存储组root.group1TTL,这将使得该存储组接受任意时刻的数据。
  • 显示 TTL
  1. SHOW ALL TTL
  2. SHOW TTL ON StorageGroupNames
  3. Eg.1 SHOW ALL TTL
  4. 这个例子会给出所有存储组的TTL
  5. Eg.2 SHOW TTL ON root.group1,root.group2,root.group3
  6. 这个例子会显示指定的三个存储组的TTL
  7. 注意: 没有设置TTL的存储组的TTL将显示为null

注意:当您对某个存储组设置TTL的时候,超过TTL范围的数据将会立即不可见。但由于数据文件可能混合包含处在TTL范围内 与范围外的数据,同时数据文件可能正在接受查询,数据文件的物理删除不会立即进行。如果你在此时取消或者调大TTL, 一部分之前不可见的数据可能重新可见,而那些已经被物理删除的数据则将永久丢失。也就是说,TTL操作不会原子性地删除 对应的数据。因此我们不推荐您频繁修改TTL,除非您能接受该操作带来的一定程度的不可预知性。

  • 删除时间分区 (实验性功能)
  1. DELETE PARTITION StorageGroupName INT(COMMA INT)*
  2. Eg DELETE PARTITION root.sg1 0,1,2
  3. 该例子将删除存储组root.sg1的前三个时间分区

partitionId 可以通过查看数据文件夹获取,或者是计算 timestamp / partitionInterval得到。

性能追踪

IoTDB 支持使用 TRACING 语句来追踪查询语句的执行,通过日志文件输出该查询访问的 Tsfile 文件数,chunk 数等信息,默认输出位置位于 ./data/tracing. 性能追踪功能默认处于关闭状态,用户可以使用 TRACING ON/OFF 命令来打开/关闭该功能。

  1. TRACING ON //打开性能追踪
  2. TRACING OFF //关闭性能追踪

中止查询

  • 显示正在执行的查询列表
  1. SHOW QUERY PROCESSLIST
  • 中止查询
  1. KILL QUERY INT?
  2. E.g. KILL QUERY
  3. E.g. KILL QUERY 2

设置系统为只读/可写入模式

  1. IoTDB> SET SYSTEM TO READONLY
  2. IoTDB> SET SYSTEM TO WRITABLE

标识符列表

  1. QUOTE := '\'';
  2. DOT := '.';
  3. COLON : ':' ;
  4. COMMA := ',' ;
  5. SEMICOLON := ';' ;
  6. LPAREN := '(' ;
  7. RPAREN := ')' ;
  8. LBRACKET := '[';
  9. RBRACKET := ']';
  10. EQUAL := '=' | '==';
  11. NOTEQUAL := '<>' | '!=';
  12. LESSTHANOREQUALTO := '<=';
  13. LESSTHAN := '<';
  14. GREATERTHANOREQUALTO := '>=';
  15. GREATERTHAN := '>';
  16. DIVIDE := '/';
  17. PLUS := '+';
  18. MINUS := '-';
  19. STAR := '*';
  20. Letter := 'a'..'z' | 'A'..'Z';
  21. HexDigit := 'a'..'f' | 'A'..'F';
  22. Digit := '0'..'9';
  23. Boolean := TRUE | FALSE | 0 | 1 (case insensitive)
  1. StringLiteral := ( '\'' ( ~('\'') )* '\'' | '\"' ( ~('\"') )* '\"');
  2. eg. 'abc'
  3. eg. "abc"
  1. Integer := ('-' | '+')? Digit+;
  2. eg. 123
  3. eg. -222
  1. Float := ('-' | '+')? Digit+ DOT Digit+ (('e' | 'E') ('-' | '+')? Digit+)?;
  2. eg. 3.1415
  3. eg. 1.2E10
  4. eg. -1.33
  1. Identifier := (Letter | '_') (Letter | Digit | '_' | MINUS)*;
  2. eg. a123
  3. eg. _abc123

常量列表

  1. PointValue : Integer | Float | StringLiteral | Boolean
  1. TimeValue : Integer | DateTime | ISO8601 | NOW()
  2. Note: Integer means timestamp type.
  3. DateTime :
  4. eg. 2016-11-16T16:22:33+08:00
  5. eg. 2016-11-16 16:22:33+08:00
  6. eg. 2016-11-16T16:22:33.000+08:00
  7. eg. 2016-11-16 16:22:33.000+08:00
  8. Note: DateTime Type can support several types, see Chapter 3 Datetime section for details.
  1. PrecedenceEqualOperator : EQUAL | NOTEQUAL | LESSTHANOREQUALTO | LESSTHAN | GREATERTHANOREQUALTO | GREATERTHAN
  1. Timeseries : ROOT [DOT <LayerName>]* DOT <SensorName>
  2. LayerName : Identifier
  3. SensorName : Identifier
  4. eg. root.ln.wf01.wt01.status
  5. eg. root.sgcc.wf03.wt01.temperature
  6. Note: Timeseries must be start with `root`(case insensitive) and end with sensor name.
  1. PrefixPath : ROOT (DOT <LayerName>)*
  2. LayerName : Identifier | STAR
  3. eg. root.sgcc
  4. eg. root.*
  1. Path: (ROOT | <LayerName>) (DOT <LayerName>)*
  2. LayerName: Identifier | STAR
  3. eg. root.ln.wf01.wt01.status
  4. eg. root.*.wf01.wt01.status
  5. eg. root.ln.wf01.wt01.*
  6. eg. *.wt01.*
  7. eg. *