IoTDB学习笔记

本文介绍IoTDB的安装、配置及基本操作,包括创建存储组、时间序列,数据的插入与查询等。涵盖客户端使用、命令语法示例及数据库管理等方面。

1、下载地址
    https://www.apache.org/dyn/closer.cgi/iotdb/0.13.0/apache-iotdb-0.13.0-all-bin.zip
    
2、解压
    unzip apache-iotdb-0.13.0-all-bin.zip
    
3、启动服务端
    进入到 apache-iotdb-0.13.0-all-bin目录
    
    liux
        nohup sbin/start-server.sh >/dev/null 2>&1 &  或者 nohup sbin/start-server.sh -c <conf_path> -rpc_port <rpc_port> >/dev/null 2>&1 &
    Windows
        sbin\start-server.bat -c <conf_path> -rpc_port <rpc_port>

4、使用客户端
    安装 IoTDB 后,有一个默认用户“root”,其默认密码也是“root”; 默认参数为“-h 127.0.0.1 -p 6667 -u root -pw -root”。
    
    linux
        sbin/start-cli.sh -h 127.0.0.1 -p 6667 -u root -pw root 或者 sbin/start-cli.sh
    Windows
        sbin\start-cli.bat -h 127.0.0.1 -p 6667 -u root -pw root
    
    
5、基本命令
    1、定义一个存储组
        SET STORAGE GROUP TO root.ln
    2、查看创建的存储组
        SHOW STORAGE GROUP
    3、创建时间序列,定义数据类型和编码方案
        CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN
        CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE
    4、查询系统中的所有时间序列
        SHOW TIMESERIES
    5、查询特定时间序列
        SHOW TIMESERIES root.ln.wf01.wt01.status
    6、插入时序数据
        INSERT INTO root.ln.wf01.wt01(timestamp,status) values(100,true);
        INSERT INTO root.ln.wf01.wt01(timestamp,status,temperature) values(200,false,20.71)
    7、查询指定时间序列的数据
        SELECT status FROM root.ln.wf01.wt01
    8、查询多个时间序列数据
        SELECT * FROM root.ln.wf01.wt01
        
6、退出客户端 Cli
    quit 或者 exit
    
7、停止IoTDB数据库
    linux
        sbin/stop-server.sh
    Windows
        sbin\stop-server.bat
    
8、显示版本
    show version
    
9、设置存储组
    SET STORAGE GROUP TO <FullPath>
    例: SET STORAGE GROUP TO root.ln.wf01.wt01
    
10、删除存储组
    DELETE STORAGE GROUP <PathPattern> [COMMA <PathPattern>]*
    例:DELETE STORAGE GROUP root.ln.wf01.wt01
        DELETE STORAGE GROUP root.ln.wf01.wt01, root.ln.wf01.wt02
        DELETE STORAGE GROUP root.ln.wf01.*
        DELETE STORAGE GROUP root.**

11、创建时间序列语句
    CREATE TIMESERIES <FullPath> WITH <AttributeClauses>
    alias
        : LR_BRACKET ID RR_BRACKET
        ;
    attributeClauses
        : DATATYPE OPERATOR_EQ <DataTypeValue> 
        COMMA ENCODING OPERATOR_EQ <EncodingValue>
        (COMMA (COMPRESSOR | COMPRESSION) OPERATOR_EQ <CompressorValue>)?
        (COMMA property)*
        tagClause
        attributeClause
        ;
    attributeClause
        : ATTRIBUTES LR_BRACKET propertyClause (COMMA propertyClause)* RR_BRACKET
        ;
    tagClause
        : TAGS LR_BRACKET propertyClause (COMMA propertyClause)* RR_BRACKET
        ;
    propertyClause
        : name=ID OPERATOR_EQ propertyValue
        ;
    DataTypeValue: BOOLEAN | DOUBLE | FLOAT | INT32 | INT64 | TEXT
    EncodingValue: GORILLA | PLAIN | RLE | TS_2DIFF | REGULAR
    CompressorValue: UNCOMPRESSED | SNAPPY
    AttributesType: SDT | COMPDEV | COMPMINTIME | COMPMAXTIME
    PropertyValue: ID | constant
    例:
        CREATE TIMESERIES root.ln.wf01.wt01.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN
        CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE
        CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE, COMPRESSOR=SNAPPY, MAX_POINT_NUMBER=3
        CREATE TIMESERIES root.turbine.d0.s0(temperature) WITH DATATYPE=FLOAT, ENCODING=RLE, COMPRESSOR=SNAPPY tags(unit=f, description='turbine this is a test1') attributes(H_Alarm=100, M_Alarm=50)
        CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE, LOSS=SDT, COMPDEV=0.01
        CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE, LOSS=SDT, COMPDEV=0.01, COMPMINTIME=3
        CREATE TIMESERIES root.ln.wf01.wt01.temperature WITH DATATYPE=FLOAT, ENCODING=RLE, LOSS=SDT, COMPDEV=0.01, COMPMINTIME=2, COMPMAXTIME=15

12、创建时间序列语句(简化版,从 v0.13 开始)
    CREATE TIMESERIES <FullPath> <SimplifiedAttributeClauses>
    SimplifiedAttributeClauses
        : WITH? (DATATYPE OPERATOR_EQ)? <DataTypeValue> 
        ENCODING OPERATOR_EQ <EncodingValue>
        ((COMPRESSOR | COMPRESSION) OPERATOR_EQ <CompressorValue>)?
        (COMMA property)*
        tagClause
        attributeClause
        ;
    例:CREATE TIMESERIES root.ln.wf01.wt01.status BOOLEAN ENCODING=PLAIN
        CREATE TIMESERIES root.ln.wf01.wt01.temperature FLOAT ENCODING=RLE
        CREATE TIMESERIES root.ln.wf01.wt01.temperature FLOAT ENCODING=RLE COMPRESSOR=SNAPPY MAX_POINT_NUMBER=3
        CREATE TIMESERIES root.turbine.d0.s0(temperature) FLOAT ENCODING=RLE COMPRESSOR=SNAPPY tags(unit=f, description='turbine this is a test1') attributes(H_Alarm=100, M_Alarm=50)
        CREATE TIMESERIES root.ln.wf01.wt01.temperature FLOAT ENCODING=RLE LOSS=SDT COMPDEV=0.01
        CREATE TIMESERIES root.ln.wf01.wt01.temperature FLOAT ENCODING=RLE LOSS=SDT COMPDEV=0.01 COMPMINTIME=3
        CREATE TIMESERIES root.ln.wf01.wt01.temperature FLOAT ENCODING=RLE LOSS=SDT COMPDEV=0.01 COMPMINTIME=2 COMPMAXTIME=15

13、创建对齐的时间序列语句
    CREATE ALIGNED TIMESERIES <FullPath> alignedMeasurements
    alignedMeasurements
        : LR_BRACKET nodeNameWithoutWildcard attributeClauses
        (COMMA nodeNameWithoutWildcard attributeClauses)+ RR_BRACKET
        ;
    例: CREATE ALIGNED TIMESERIES root.ln.wf01.GPS(lat FLOAT ENCODING=GORILLA, lon FLOAT ENCODING=GORILLA COMPRESSOR=SNAPPY)
    
14、创建模式模板语句
    CREATE SCHEMA TEMPLATE <TemplateName> LR_BRACKET <TemplateMeasurementClause> (COMMA plateMeasurementClause>)* RR_BRACKET
    templateMeasurementClause
        : suffixPath attributeClauses #nonAlignedTemplateMeasurement
        | suffixPath LR_BRACKET nodeNameWithoutWildcard attributeClauses 
        (COMMA nodeNameWithoutWildcard attributeClauses)+ RR_BRACKET #alignedTemplateMeasurement
        ;
    例: CREATE SCHEMA TEMPLATE temp1(
            s1 INT32 encoding=Gorilla, compression=SNAPPY,
            vector1(
                s1 INT32 encoding=Gorilla,
                s2 FLOAT encoding=RLE, compression=SNAPPY)
        )
    
15、设置模式模板语句
    SET SCHEMA TEMPLATE <TemplateName> TO <PrefixPath>
    例: SET SCHEMA TEMPLATE temp1 TO root.beijing
    
16、创建模式模板语句的时间序列
    CREATE TIMESERIES OF SCHEMA TEMPLATE ON <PrefixPath>
    例: CREATE TIMESERIES OF SCHEMA TEMPLATE ON root.beijing
    
17、取消设置模式模板语句
    UNSET SCHEMA TEMPLATE <TemplateName> FROM <PrefixPath>
    例: UNSET SCHEMA TEMPLATE temp1 FROM root.beijing

18、删除时间序列语句
    DELETE TIMESERIES <PathPattern> [COMMA <PathPattern>]*
    例: DELETE TIMESERIES root.ln.wf01.wt01.status
        DELETE TIMESERIES root.ln.wf01.wt01.status, root.ln.wf01.wt01.temperature
        DELETE TIMESERIES root.ln.wf01.wt01.*

19、更改时间序列声明
    ALTER TIMESERIES fullPath alterClause
    alterClause
        : RENAME beforeName=ID TO currentName=ID
        | SET property (COMMA property)*
        | DROP ID (COMMA ID)*
        | ADD TAGS property (COMMA property)*
        | ADD ATTRIBUTES property (COMMA property)*
        | UPSERT tagClause attributeClause
        ;
    attributeClause
        : (ATTRIBUTES LR_BRACKET property (COMMA property)* RR_BRACKET)?
        ;
    tagClause
        : (TAGS LR_BRACKET property (COMMA property)* RR_BRACKET)?
        ;
    例: ALTER timeseries root.turbine.d1.s1 RENAME tag1 TO newTag1
        ALTER timeseries root.turbine.d1.s1 SET tag1=newV1, attr1=newV1
        ALTER timeseries root.turbine.d1.s1 DROP tag1, tag2
        ALTER timeseries root.turbine.d1.s1 ADD TAGS tag3=v3, tag4=v4
        ALTER timeseries root.turbine.d1.s1 ADD ATTRIBUTES attr3=v3, attr4=v4
        ALTER timeseries root.turbine.d1.s1 UPSERT TAGS(tag2=newV2, tag3=v3) ATTRIBUTES(attr3=v3, attr4=v4)

20、显示所有时间序列语句
    SHOW TIMESERIES
    例: SHOW TIMESERIES

21、显示特定时间序列语句
    SHOW TIMESERIES <Path>
    例: SHOW TIMESERIES root.**
        SHOW TIMESERIES root.ln.**
        SHOW TIMESERIES root.ln.*.*.status
        SHOW TIMESERIES root.ln.wf01.wt01.status

22、使用 where 子句显示特定时间序列语句
    SHOW TIMESERIES pathPattern? showWhereClause?
    showWhereClause
        : WHERE (property | containsExpression)
        ;
    containsExpression
        : name=ID OPERATOR_CONTAINS value=propertyValue
        ;

    例: show timeseries root.ln.** where unit='c'
        show timeseries root.ln.** where description contains 'test1'

23、显示带有 where 子句的特定时间序列语句从偏移量开始并限制结果的总数
    SHOW TIMESERIES pathPattern? showWhereClause? limitClause?

    showWhereClause
        : WHERE (property | containsExpression)
        ;
    containsExpression
        : name=ID OPERATOR_CONTAINS value=propertyValue
        ;
    limitClause
        : LIMIT INT offsetClause?
        | offsetClause? LIMIT INT
        ;
        
    Eg: show timeseries root.ln.** where unit='c'
    Eg: show timeseries root.ln.** where description contains 'test1'
    Eg: show timeseries root.ln.** where unit='c' limit 10 offset 10

24、显示存储组声明
    SHOW STORAGE GROUP
    Eg: IoTDB > SHOW STORAGE GROUP
    Note: This statement can be used in IoTDB Client and JDBC.

25、显示特定存储组声明
    SHOW STORAGE GROUP <Path>
    Eg: IoTDB > SHOW STORAGE GROUP root.*
    Eg: IoTDB > SHOW STORAGE GROUP root.ln
    Note: The path can be full path or path pattern.
    Note: This statement can be used in IoTDB Client and JDBC.

26、显示合并状态语句
    SHOW MERGE INFO
    Eg: IoTDB > SHOW MERGE INFO
    Note: This statement can be used in IoTDB Client and JDBC.

27、计数时间序列语句
    COUNT TIMESERIES <Path>
    Eg: IoTDB > COUNT TIMESERIES root.**
    Eg: IoTDB > COUNT TIMESERIES root.ln.**
    Eg: IoTDB > COUNT TIMESERIES root.ln.*.*.status
    Eg: IoTDB > COUNT TIMESERIES root.ln.wf01.wt01.status
    Note: The path can be timeseries path or path pattern.
    Note: This statement can be used in IoTDB Client and JDBC.

    COUNT TIMESERIES <Path> GROUP BY LEVEL=<INTEGER>
    Eg: IoTDB > COUNT TIMESERIES root.** GROUP BY LEVEL=1
    Eg: IoTDB > COUNT TIMESERIES root.ln.** GROUP BY LEVEL=2
    Eg: IoTDB > COUNT TIMESERIES root.ln.wf01.* GROUP BY LEVEL=3
    Note: The path can be timeseries path or path pattern.
    Note: This statement can be used in IoTDB Client and JDBC.

28、计数节点语句
    COUNT NODES <Path> LEVEL=<INTEGER>
    Eg: IoTDB > COUNT NODES root.** LEVEL=2
    Eg: IoTDB > COUNT NODES root.ln.** LEVEL=2
    Eg: IoTDB > COUNT NODES root.ln.* LEVEL=3
    Eg: IoTDB > COUNT NODES root.ln.wf01 LEVEL=3
    Note: The path can be full path or path pattern.
    Note: This statement can be used in IoTDB Client and JDBC.

29、显示所有设备声明
    SHOW DEVICES (WITH STORAGE GROUP)? limitClause? 
    Eg: IoTDB > SHOW DEVICES
    Eg: IoTDB > SHOW DEVICES WITH STORAGE GROUP
    Note: This statement can be used in IoTDB Client and JDBC.

30、显示特定设备声明
    SHOW DEVICES <PathPattern> (WITH STORAGE GROUP)? limitClause?
    Eg: IoTDB > SHOW DEVICES root.**
    Eg: IoTDB > SHOW DEVICES root.ln.**
    Eg: IoTDB > SHOW DEVICES root.*.wf01
    Eg: IoTDB > SHOW DEVICES root.ln WITH STORAGE GROUP
    Eg: IoTDB > SHOW DEVICES root.*.wf01 WITH STORAGE GROUP
    Note: This statement can be used in IoTDB Client and JDBC.

31、显示根语句的子路径
    SHOW CHILD PATHS
    Eg: IoTDB > SHOW CHILD PATHS
    Note: This statement can be used in IoTDB Client and JDBC.

32、显示子路径语句
    SHOW CHILD PATHS <PathPattern>
    Eg: IoTDB > SHOW CHILD PATHS root
    Eg: IoTDB > SHOW CHILD PATHS root.ln
    Eg: IoTDB > SHOW CHILD PATHS root.*.wf01
    Eg: IoTDB > SHOW CHILD PATHS root.ln.wf* 
    Note: This statement can be used in IoTDB Client and JDBC.

#数据管理声明
33、插入记录语句
    INSERT INTO <PrefixPath> LPAREN TIMESTAMP COMMA <Sensor> [COMMA <Sensor>]* RPAREN VALUES LPAREN <TimeValue>, <PointValue> [COMMA <PointValue>]* RPAREN
    Sensor : Identifier
    Eg: IoTDB > INSERT INTO root.ln.wf01.wt01(timestamp,status) values(1509465600000,true)
    Eg: IoTDB > INSERT INTO root.ln.wf01.wt01(timestamp,status) VALUES(NOW(), false)
    Eg: IoTDB > INSERT INTO root.ln.wf01.wt01(timestamp,temperature) VALUES(2017-11-01T00:17:00.000+08:00,24.22028)
    Eg: IoTDB > INSERT INTO root.ln.wf01.wt01(timestamp,status,temperature) VALUES (1509466680000,false,20.060787)
    Eg: IoTDB > INSERT INTO root.sg.d1(timestamp,(s1,s2),(s3,s4)) VALUES (1509466680000,(1.0,2),(NULL,4))
    Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>
    Note: The order of Sensor and PointValue need one-to-one correspondence

34、删除记录声明
    DELETE FROM <PathPattern> [COMMA <PathPattern>]* [WHERE <WhereClause>]?
    WhereClause : <Condition> [(AND) <Condition>]*
    Condition  : <TimeExpr> [(AND) <TimeExpr>]*
    TimeExpr : TIME PrecedenceEqualOperator (<TimeValue> | <RelativeTime>)
    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
    Eg: DELETE FROM root.ln.wf01.wt01.status, root.ln.wf01.wt01.temperature WHERE time < NOW()
    Eg: DELETE FROM root.ln.wf01.wt01.* WHERE time >= 1509466140000

35、选择记录声明
    SELECT <SelectClause> FROM <FromClause> [WHERE <WhereClause>]?
    SelectClause : <SelectPath> (COMMA <SelectPath>)*
    SelectPath : <FUNCTION> LPAREN <Path> RPAREN | <Path>
    FUNCTION : ‘COUNT’ , ‘MIN_TIME’, ‘MAX_TIME’, ‘MIN_VALUE’, ‘MAX_VALUE’
    FromClause : <PrefixPath> (COMMA <PrefixPath>)?
    WhereClause : <Condition> [(AND | OR) <Condition>]*
    Condition  : <Expression> [(AND | OR) <Expression>]*
    Expression : [NOT | !]? <TimeExpr> | [NOT | !]? <SensorExpr>
    TimeExpr : TIME PrecedenceEqualOperator (<TimeValue> | <RelativeTime>)
    RelativeTimeDurationUnit = Integer ('Y'|'MO'|'W'|'D'|'H'|'M'|'S'|'MS'|'US'|'NS')
    RelativeTime : (now() | <TimeValue>) [(+|-) RelativeTimeDurationUnit]+
    SensorExpr : (<Timeseries> | <Path>) PrecedenceEqualOperator <PointValue>
    Eg: IoTDB > SELECT status, temperature FROM root.ln.wf01.wt01 WHERE temperature < 24 and time > 2017-11-1 0:13:00
    Eg. IoTDB > SELECT ** FROM root
    Eg. IoTDB > SELECT * FROM root.**
    Eg. IoTDB > SELECT * FROM root where time > now() - 5m
    Eg. IoTDB > SELECT * FROM root.ln.*.wf*
    Eg. IoTDB > SELECT COUNT(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 25
    Eg. IoTDB > SELECT MIN_TIME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 25
    Eg. IoTDB > SELECT MAX_TIME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature > 24
    Eg. IoTDB > SELECT MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature > 23
    Eg. IoTDB > SELECT MAX_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 25
    Eg. IoTDB > SELECT COUNT(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 25 GROUP BY LEVEL=1
    Note: the statement needs to satisfy this constraint: <Path>(SelectClause) + <PrefixPath>(FromClause) = <Timeseries>
    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>
    Note: In Version 0.7.0, if <WhereClause> includes `OR`, time filter can not be used.
    Note: There must be a space on both sides of the plus and minus operator appearing in the time expression 

36、按语句分组
    SELECT <SelectClause> FROM <FromClause> WHERE  <WhereClause> GROUP BY <GroupByTimeClause>
    SelectClause : <Function> [COMMA < Function >]*
    Function : <AggregationFunction> LPAREN <Path> RPAREN
    FromClause : <PrefixPath>
    WhereClause : <Condition> [(AND | OR) <Condition>]*
    Condition  : <Expression> [(AND | OR) <Expression>]*
    Expression : [NOT | !]? <TimeExpr> | [NOT | !]? <SensorExpr>
    TimeExpr : TIME PrecedenceEqualOperator (<TimeValue> | <RelativeTime>)
    RelativeTimeDurationUnit = Integer ('Y'|'MO'|'W'|'D'|'H'|'M'|'S'|'MS'|'US'|'NS')
    RelativeTime : (now() | <TimeValue>) [(+|-) RelativeTimeDurationUnit]+
    SensorExpr : (<Timeseries> | <Path>) PrecedenceEqualOperator <PointValue>
    GroupByTimeClause : LPAREN <TimeInterval> COMMA <TimeUnit> (COMMA <TimeUnit>)? RPAREN
    TimeInterval: LSBRACKET <TimeValue> COMMA <TimeValue> RRBRACKET | LRBRACKET <TimeValue> COMMA <TimeValue> RSBRACKET
    TimeUnit : Integer <DurationUnit>
    DurationUnit : "ms" | "s" | "m" | "h" | "d" | "w" | "mo"
    Eg: SELECT COUNT(status), COUNT(temperature) FROM root.ln.wf01.wt01 where temperature < 24 GROUP BY([1509465720000, 1509466380000), 5m)
    Eg: SELECT COUNT(status), COUNT(temperature) FROM root.ln.wf01.wt01 where temperature < 24 GROUP BY((1509465720000, 1509466380000], 5m)
    Eg. SELECT COUNT (status), MAX_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE time < 1509466500000 GROUP BY([1509465720000, 1509466380000), 5m, 10m)
    Eg. SELECT MIN_TIME(status), MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE temperature < 25 GROUP BY ([1509466140000, 1509466380000), 3m, 5ms)
    Eg. SELECT MIN_TIME(status), MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE temperature < 25 GROUP BY ((1509466140000, 1509466380000], 3m, 5ms)
    Eg. SELECT MIN_TIME(status), MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE temperature < 25 GROUP BY ((1509466140000, 1509466380000], 1mo)
    Eg. SELECT MIN_TIME(status), MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE temperature < 25 GROUP BY ((1509466140000, 1509466380000], 1mo, 1mo)
    Eg. SELECT MIN_TIME(status), MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE temperature < 25 GROUP BY ((1509466140000, 1509466380000], 1mo, 2mo)
    Note: the statement needs to satisfy this constraint: <Path>(SelectClause) + <PrefixPath>(FromClause) = <Timeseries>
    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>
    Note: <TimeValue>(TimeInterval) needs to be greater than 0
    Note: First <TimeValue>(TimeInterval) in needs to be smaller than second <TimeValue>(TimeInterval)
    Note: <TimeUnit> needs to be greater than 0
    Note: Third <TimeUnit> if set shouldn't be smaller than second <TimeUnit>
    Note: If the second <DurationUnit> is "mo", the third <DurationUnit> need to be in month
    Note: If the third <DurationUnit> is "mo", the second <DurationUnit> can be in any unit

37、填充声明
    SELECT <SelectClause> FROM <FromClause> WHERE <WhereClause> FILL <FillClause>
    SelectClause : <Path> [COMMA <Path>]*
    FromClause : < PrefixPath > [COMMA < PrefixPath >]*
    WhereClause : <WhereExpression>
    WhereExpression : TIME EQUAL <TimeValue>
    FillClause : LPAREN <TypeClause> [COMMA <TypeClause>]* RPAREN
    TypeClause : <Int32Clause> | <Int64Clause> | <FloatClause> | <DoubleClause> | <BoolClause> | <TextClause>
    Int32Clause: INT32 LBRACKET (<LinearClause> | <PreviousClause>)  RBRACKET
    Int64Clause: INT64 LBRACKET (<LinearClause> | <PreviousClause>)  RBRACKET
    FloatClause: FLOAT LBRACKET (<LinearClause> | <PreviousClause>)  RBRACKET
    DoubleClause: DOUBLE LBRACKET (<LinearClause> | <PreviousClause>)  RBRACKET
    BoolClause: BOOLEAN LBRACKET (<LinearClause> | <PreviousClause>)  RBRACKET
    TextClause: TEXT LBRACKET (<LinearClause> | <PreviousClause>)  RBRACKET
    PreviousClause : PREVIOUS [COMMA <ValidPreviousTime>]?
    LinearClause : LINEAR [COMMA <ValidPreviousTime> COMMA <ValidBehindTime>]?
    ValidPreviousTime, ValidBehindTime: <TimeUnit>
    TimeUnit : Integer <DurationUnit>
    DurationUnit : "ms" | "s" | "m" | "h" | "d" | "w"
    Eg: SELECT temperature FROM root.ln.wf01.wt01 WHERE time = 2017-11-01T16:37:50.000 FILL(float[previous, 1m])
    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])
    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])
    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])
    Note: the statement needs to satisfy this constraint: <PrefixPath>(FromClause) + <Path>(SelectClause) = <Timeseries>
    Note: Integer in <TimeUnit> needs to be greater than 0

38、按填充语句分组
    SELECT <SelectClause> FROM <FromClause> WHERE  <WhereClause> GROUP BY <GroupByClause> (FILL <GROUPBYFillClause>)?
    GroupByClause : LPAREN <TimeInterval> COMMA <TimeUnit> RPAREN
    GROUPBYFillClause : LPAREN <TypeClause> RPAREN
    TypeClause : <AllClause> | <Int32Clause> | <Int64Clause> | <FloatClause> | <DoubleClause> | <BoolClause> | <TextClause> 
    AllClause: ALL LBRACKET (<PreviousUntilLastClause> | <PreviousClause>)  RBRACKET
    Int32Clause: INT32 LBRACKET (<PreviousUntilLastClause> | <PreviousClause>)  RBRACKET
    Int64Clause: INT64 LBRACKET (<PreviousUntilLastClause> | <PreviousClause>)  RBRACKET
    FloatClause: FLOAT LBRACKET (<PreviousUntilLastClause> | <PreviousClause>)  RBRACKET
    DoubleClause: DOUBLE LBRACKET (<PreviousUntilLastClause> | <PreviousClause>)  RBRACKET
    BoolClause: BOOLEAN LBRACKET (<PreviousUntilLastClause> | <PreviousClause>)  RBRACKET
    TextClause: TEXT LBRACKET (<PreviousUntilLastClause> | <PreviousClause>)  RBRACKET
    PreviousClause : PREVIOUS
    PreviousUntilLastClause : PREVIOUSUNTILLAST
    Eg: SELECT last_value(temperature) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (float[PREVIOUS])
    Eg: SELECT last_value(temperature) FROM root.ln.wf01.wt01 GROUP BY((15, 100], 5m) FILL (float[PREVIOUS])
    Eg: SELECT last_value(power) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (int32[PREVIOUSUNTILLAST])
    Eg: SELECT last_value(power) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (int32[PREVIOUSUNTILLAST, 5m])
    Eg: SELECT last_value(temperature), last_value(power) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (ALL[PREVIOUS])
    Eg: SELECT last_value(temperature), last_value(power) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (ALL[PREVIOUS, 5m])
    Note: In group by fill, sliding step is not supported in group by clause
    Note: Now, only last_value aggregation function is supported in group by fill.
    Note: Linear fill is not supported in group by fill.

39、按时间排序声明
    SELECT <SelectClause> FROM <FromClause> WHERE  <WhereClause> GROUP BY <GroupByClause> (FILL <GROUPBYFillClause>)? orderByTimeClause?
    orderByTimeClause: order by time (asc | desc)?

    Eg: SELECT last_value(temperature) FROM root.ln.wf01.wt01 GROUP BY([20, 100), 5m) FILL (float[PREVIOUS]) order by time desc
    Eg: SELECT * from root.** order by time desc
    Eg: SELECT * from root.** order by time desc align by device 
    Eg: SELECT * from root.** order by time desc disable align
    Eg: SELECT last * from root.** order by time desc

40、限制查询结果记录数和起始位置偏移量声明
    SELECT <SelectClause> FROM <FromClause> [WHERE <WhereClause>] [<LIMITClause>] [<SLIMITClause>]
    SelectClause : [<Path> | Function]+
    Function : <AggregationFunction> LPAREN <Path> RPAREN
    FromClause : <Path>
    WhereClause : <Condition> [(AND | OR) <Condition>]*
    Condition : <Expression> [(AND | OR) <Expression>]*
    Expression: [NOT|!]?<TimeExpr> | [NOT|!]?<SensorExpr>
    TimeExpr : TIME PrecedenceEqualOperator (<TimeValue> | <RelativeTime>)
    RelativeTimeDurationUnit = Integer ('Y'|'MO'|'W'|'D'|'H'|'M'|'S'|'MS'|'US'|'NS')
    RelativeTime : (now() | <TimeValue>) [(+|-) RelativeTimeDurationUnit]+
    SensorExpr : (<Timeseries>|<Path>) PrecedenceEqualOperator <PointValue>
    LIMITClause : LIMIT <N> [OFFSETClause]?
    N : Integer
    OFFSETClause : OFFSET <OFFSETValue>
    OFFSETValue : Integer
    SLIMITClause : SLIMIT <SN> [SOFFSETClause]?
    SN : Integer
    SOFFSETClause : SOFFSET <SOFFSETValue>
    SOFFSETValue : Integer
    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
    Eg. IoTDB > SELECT COUNT (status), MAX_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE time < 1509466500000 GROUP BY([1509465720000, 1509466380000], 5m) LIMIT 3
    Note: N, OFFSETValue, SN and SOFFSETValue must be greater than 0.
    Note: The order of <LIMITClause> and <SLIMITClause> does not affect the grammatical correctness.
    Note: <FillClause> can not use <LIMITClause> but not <SLIMITClause>.

41、按设备对齐语句
    AlignbyDeviceClause : ALIGN BY DEVICE

    Rules:  
    1. Both uppercase and lowercase are ok.  
    Correct example: select * from root.sg1.* align by device  
    Correct example: select * from root.sg1.* ALIGN BY DEVICE  

    2. AlignbyDeviceClause can only be used at the end of a query statement.  
    Correct example: select * from root.sg1.* where time > 10 align by device  
    Wrong example: select * from root.sg1.* align by device where time > 10  

    3. The paths of the SELECT clause can only be single level. In other words, the paths of the SELECT clause can only be measurements or STAR, without DOT.
    Correct example: select s0,s1 from root.sg1.* align by device  
    Correct example: select s0,s1 from root.sg1.d0, root.sg1.d1 align by device  
    Correct example: select * from root.sg1.* align by device  
    Correct example: select * from root.** align by device  
    Correct example: select s0,s1,* from root.*.* align by device  
    Wrong example: select d0.s1, d0.s2, d1.s0 from root.sg1 align by device  
    Wrong example: select *.s0, *.s1 from root.* align by device  
    Wrong example: select *.*.* from root align by device

    4. The data types of the same measurement column should be the same across devices. 
    Note that when it comes to aggregated paths, the data type of the measurement column will reflect 
    the aggregation function rather than the original timeseries.

    Correct example: select s0 from root.sg1.d0,root.sg1.d1 align by device   
    root.sg1.d0.s0 and root.sg1.d1.s0 are both INT32.  

    Correct example: select count(s0) from root.sg1.d0,root.sg1.d1 align by device   
    count(root.sg1.d0.s0) and count(root.sg1.d1.s0) are both INT64.  

    Wrong example: select s0 from root.sg1.d0, root.sg2.d3 align by device  
    root.sg1.d0.s0 is INT32 while root.sg2.d3.s0 is FLOAT. 

    5. The display principle of the result table is that all the columns (no matther whther a column has has existing data) will be shown, with nonexistent cells being null. Besides, the select clause support const column (e.g., 'a', '123' etc..).  
    For example, "select s0,s1,s2,'abc',s1,s2 from root.sg.d0, root.sg.d1, root.sg.d2 align by device". Suppose that the actual existing timeseries are as follows:  
    - root.sg.d0.s0
    - root.sg.d0.s1
    - root.sg.d1.s0

    Then you could expect a table like:  

    | Time | Device   | s0 | s1 |  s2  | 'abc' | s1 |  s2  |
    | ---  | ---      | ---| ---| null | 'abc' | ---| null |
    |  1   |root.sg.d0| 20 | 2.5| null | 'abc' | 2.5| null |
    |  2   |root.sg.d0| 23 | 3.1| null | 'abc' | 3.1| null |
    | ...  | ...      | ...| ...| null | 'abc' | ...| null |
    |  1   |root.sg.d1| 12 |null| null | 'abc' |null| null |
    |  2   |root.sg.d1| 19 |null| null | 'abc' |null| null |
    | ...  | ...      | ...| ...| null | 'abc' | ...| null |

    Note that the cells of measurement 's0' and device 'root.sg.d1' are all null.    

    6. The duplicated devices in the prefix paths are neglected.  
    For example, "select s0,s1 from root.sg.d0,root.sg.d0,root.sg.d1 align by device" is equal to "select s0,s1 from root.sg.d0,root.sg.d1 align by device".  
    For example. "select s0,s1 from root.sg.*,root.sg.d0 align by device" is equal to "select s0,s1 from root.sg.* align by device".  

    7. The duplicated measurements in the suffix paths are not neglected.  
    For example, "select s0,s0,s1 from root.sg.* align by device" is not equal to "select s0,s1 from root.sg.* align by device".

    8. Both time predicates and value predicates are allowed in Where Clause. The paths of the value predicates can be the leaf node or full path started with ROOT. And wildcard is not allowed here. For example:
    - select * from root.sg.* where time = 1 align by device
    - select * from root.sg.* where s0 < 100 align by device
    - select * from root.sg.* where time < 20 AND s0 > 50 align by device
    - select * from root.sg.d0 where root.sg.d0.s0 = 15 align by device

    9. More correct examples:
       - select * from root.vehicle.* align by device
       - select s0,s0,s1 from root.vehicle.* align by device
       - select s0,s1 from root.vehicle.* limit 10 offset 1 align by device
       - select * from root.vehicle.* slimit 10 soffset 2 align by device
       - select * from root.vehicle.* where time > 10 align by device
       - select * from root.vehicle.* where time < 10 AND s0 > 25 align by device
       - select * from root.vehicle.* where root.vehicle.d0.s0>0 align by device
       - select count(*) from root.vehicle align by device
       - select sum(*) from root.vehicle.* GROUP BY (20ms,0,[2,50]) align by device
       - select * from root.vehicle.* where time = 3 Fill(int32[previous, 5ms]) align by device

42、禁用对齐语句
    Disable Align Clause: DISABLE ALIGN

    Rules:  
    1. Both uppercase and lowercase are ok.  
    Correct example: select * from root.sg1.* disable align  
    Correct example: select * from root.sg1.* DISABLE ALIGN  

    2. Disable Align Clause can only be used at the end of a query statement.  
    Correct example: select * from root.sg1.* where time > 10 disable align 
    Wrong example: select * from root.sg1.* disable align where time > 10 

    3. Disable Align Clause cannot be used with Aggregation, Fill Statements, Group By or Group By Device Statements, but can with Limit Statements.
    Correct example: select * from root.sg1.* limit 3 offset 2 disable align
    Correct example: select * from root.sg1.* slimit 3 soffset 2 disable align
    Wrong example: select count(s0),count(s1) from root.sg1.d1 disable align
    Wrong example: select * from root.vehicle.* where root.vehicle.d0.s0>0 disable align
    Wrong example: select * from root.vehicle.* align by device disable align

    4. The display principle of the result table is that only when the column (or row) has existing data will the column (or row) be shown, with nonexistent cells being empty.

    You could expect a table like:
    | Time | root.sg.d0.s1 | Time | root.sg.d0.s2 | Time | root.sg.d1.s1 |
    | ---  | ---           | ---  | ---           | ---  | ---           |
    |  1   | 100           | 20   | 300           | 400  | 600           |
    |  2   | 300           | 40   | 800           | 700  | 900           |
    |  4   | 500           |      |               | 800  | 1000          |
    |      |               |      |               | 900  | 8000          |

    5. More correct examples: 
       - select * from root.vehicle.* disable align
       - select s0,s0,s1 from root.vehicle.* disable align
       - select s0,s1 from root.vehicle.* limit 10 offset 1 disable align
       - select * from root.vehicle.* slimit 10 soffset 2 disable align
       - select * from root.vehicle.* where time > 10 disable align


43、选择最后一条记录语句
    LAST 函数返回给定时间序列的最后一个时间值对。目前 LAST 查询不支持过​​滤器。

    SELECT LAST <SelectClause> FROM <FromClause>
    Select Clause : <Path> [COMMA <Path>]*
    FromClause : < PrefixPath > [COMMA < PrefixPath >]*
    WhereClause : <TimeExpr> [(AND | OR) <TimeExpr>]*
    TimeExpr : TIME PrecedenceEqualOperator (<TimeValue> | <RelativeTime>)

    Eg. SELECT LAST s1 FROM root.sg.d1
    Eg. SELECT LAST s1, s2 FROM root.sg.d1
    Eg. SELECT LAST s1 FROM root.sg.d1, root.sg.d2
    Eg. SELECT LAST s1 FROM root.sg.d1 where time > 100
    Eg. SELECT LAST s1, s2 FROM root.sg.d1 where time >= 500

    Rules:
    1. the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>

    2. SELECT LAST only supports time filter that contains '>' or '>=' currently.

    3. The result set of last query will always be displayed in a fixed three column table format.
    For example, "select last s1, s2 from root.sg.d1, root.sg.d2", the query result would be:

    | Time | Path          | Value | dataType |
    | ---  | ------------- |------ | -------- |
    |  5   | root.sg.d1.s1 | 100   | INT32    |
    |  2   | root.sg.d1.s2 | 400   | INT32    |
    |  4   | root.sg.d2.s1 | 250   | INT32    |
    |  9   | root.sg.d2.s2 | 600   | INT32    |

    4. It is not supported to use "diable align" in LAST query. 


44、作为声明
    As 语句为 SELECT 语句中查询的时间序列分配别名

    You can use as statement in all queries, but some rules are restricted about wildcard.

    1. Raw data query
    select s1 as speed, s2 as temperature from root.sg.d1

    The result set will be like:
    | Time | speed | temperature |
    |  ... |  ...  |     ....    |

    2. Aggregation query
    select count(s1) as s1_num, max_value(s2) as s2_max from root.sg.d1

    3. Down-frequence query
    select count(s1) as s1_num from root.sg.d1 group by ([100,500), 80ms)

    4. Align by device query
    select s1 as speed, s2 as temperature from root.sg.d1 align by device

    select count(s1) as s1_num, count(s2), count(s3) as s3_num from root.sg.d2 align by device

    5. Last Record query
    select last s1 as speed, s2 from root.sg.d1

    Rules:
    1. In addition to Align by device query,each AS statement has to corresponding to one time series exactly.

    E.g. select s1 as temperature from root.sg.*

    At this time if `root.sg.*` includes more than one device,then an exception will be thrown。

    2. In align by device query,the prefix path that each AS statement corresponding to can includes multiple device, but the suffix path can only be single sensor.

    E.g. select s1 as temperature from root.sg.*

    In this situation, it will be show correctly even if multiple devices are selected.

    E.g. select * as temperature from root.sg.d1

    In this situation, it will throws an exception if * corresponds to multiple sensors.


45、正则表达式语句
    Regexp 语句仅支持 TEXT 数据类型的时间序列上具有 Java 标准库样式的正则表达式

    SELECT <SelectClause> FROM <FromClause> WHERE  <WhereClause>
    Select Clause : <Path> [COMMA <Path>]*
    FromClause : < PrefixPath > [COMMA < PrefixPath >]*
    WhereClause : andExpression (OPERATOR_OR andExpression)*
    andExpression : predicate (OPERATOR_AND predicate)*
    predicate : (suffixPath | fullPath) REGEXP regularExpression
    regularExpression: Java standard regularexpression, like '^[a-z][0-9]$', [details](https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html)

    Eg. select s1 from root.sg.d1 where s1 regexp '^[0-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}$'
    Eg. select * from root.sg.d1 where s1 regexp '^[a-zA-Z]\w{5,17}$'
    Eg. select * from root.sg.d1 where s1 regexp '^\d{4}-\d{1,2}-\d{1,2}' and time > 100

46、类比声明
    LIKE Statement 的用法与mysql类似,但只支持TEXT数据类型的timeseries

    SELECT <SelectClause> FROM <FromClause> WHERE  <WhereClause>
    Select Clause : <Path> [COMMA <Path>]*
    FromClause : < PrefixPath > [COMMA < PrefixPath >]*
    WhereClause : andExpression (OPERATOR_OR andExpression)*
    andExpression : predicate (OPERATOR_AND predicate)*
    predicate : (suffixPath | fullPath) LIKE likeExpression
    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.

    Eg. select s1 from root.sg.d1 where s1 like 'abc'
    Eg. select s1, s2 from root.sg.d1 where s1 like 'a%bc'
    Eg. select * from root.sg.d1 where s1 like 'abc_'
    Eg. select * from root.sg.d1 where s1 like 'abc\%' and time > 100
    In this situation, '\%' means '%' will be escaped
    The result set will be like:
    | Time | Path         | Value |
    | ---  | ------------ | ----- |
    |  200 | root.sg.d1.s1| abc%  |

#数据库管理声明
47、创建用户
    CREATE USER <userName> <password>;  
    userName:=identifier  
    password:=string
    Eg: IoTDB > CREATE USER thulab 'pwd';

48、删除用户
    DROP USER <userName>;  
    userName:=identifier
    Eg: IoTDB > DROP USER xiaoming;

49、创建角色
    CREATE ROLE <roleName>;  
    roleName:=identifie
    Eg: IoTDB > CREATE ROLE admin;

50、删除角色
    DROP ROLE <roleName>;  
    roleName:=identifier
    Eg: IoTDB > DROP ROLE admin;

51、授予用户权限
    GRANT USER <userName> PRIVILEGES <privileges> ON <nodeName>;  
    userName:=identifier  
    nodeName:=identifier (DOT identifier)*  
    privileges:= string (COMMA string)*
    Eg: IoTDB > GRANT USER tempuser PRIVILEGES DELETE_TIMESERIES on root.ln;

52、授予角色权限
    GRANT ROLE <roleName> PRIVILEGES <privileges> ON <nodeName>;  
    privileges:= string (COMMA string)*  
    roleName:=identifier  
    nodeName:=identifier (DOT identifier)*
    Eg: IoTDB > GRANT ROLE temprole PRIVILEGES DELETE_TIMESERIES ON root.ln;

53、授予用户角色
    GRANT <roleName> TO <userName>;  
    roleName:=identifier  
    userName:=identifier
    Eg: IoTDB > GRANT temprole TO tempuser;

54、撤销用户权限
    REVOKE USER <userName> PRIVILEGES <privileges> ON <nodeName>;   
    privileges:= string (COMMA string)*  
    userName:=identifier  
    nodeName:=identifier (DOT identifier)*
    Eg: IoTDB > REVOKE USER tempuser PRIVILEGES DELETE_TIMESERIES on root.ln;

55、撤销角色权限
    REVOKE ROLE <roleName> PRIVILEGES <privileges> ON <nodeName>;  
    privileges:= string (COMMA string)*  
    roleName:= identifier  
    nodeName:=identifier (DOT identifier)*
    Eg: IoTDB > REVOKE ROLE temprole PRIVILEGES DELETE_TIMESERIES ON root.ln;

56、撤销用户角色
    REVOKE <roleName> FROM <userName>;
    roleName:=identifier
    userName:=identifier
    Eg: IoTDB > REVOKE temprole FROM tempuser;

57、列出用户
    LIST USER

58、列出角色
    LIST ROLE

59、列出特权
    LIST PRIVILEGES USER  <username> ON <path>;    
    username:=identifier    
    path=‘root’ (DOT identifier)*
    Eg: IoTDB > LIST PRIVILEGES USER sgcc_wirte_user ON root.sgcc;

60、列出角色的权限
    LIST ROLE PRIVILEGES <roleName>
    roleName:=identifier
    Eg: IoTDB > LIST ROLE PRIVILEGES actor;

61、列出角色的特权(在特定路径上)
    LIST PRIVILEGES ROLE <roleName> ON <path>;    
    roleName:=identifier  
    path=‘root’ (DOT identifier)*
    Eg: IoTDB > LIST PRIVILEGES ROLE wirte_role ON root.sgcc;

62、列出用户的权限
    LIST USER PRIVILEGES <username> ;   
    username:=identifier  
    Eg: IoTDB > LIST USER PRIVILEGES tempuser;

63、列出用户的角色
    LIST ALL ROLE OF USER <username> ;  
    username:=identifier
    Eg: IoTDB > LIST ALL ROLE OF USER tempuser;

64、列出角色的用户
    LIST ALL USER OF ROLE <roleName>;
    roleName:=identifier
    Eg: IoTDB > LIST ALL USER OF ROLE roleuser;

65、更改密码
    ALTER USER <username> SET PASSWORD <password>;
    roleName:=identifier
    password:=identifier
    Eg: IoTDB > ALTER USER tempuser SET PASSWORD 'newpwd';

函数
66、COUNT 函数返回 SELECT 语句选择的时间序列(一个或多个)非空值的值数。结果是一个有符号的 64 位整数。如果没有匹配的行,则 COUNT() 返回 0。
    SELECT COUNT(Path) (COMMA COUNT(Path))* FROM <FromClause> [WHERE <WhereClause>]?
    Eg. SELECT COUNT(status), COUNT(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
    Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>

67、FIRST_VALUE(Rename from FIRST at V0.10.0)
    FIRST_VALUE 函数返回所选时间序列(一个或多个)的第一个点值。

    SELECT FIRST_VALUE (Path) (COMMA FIRST_VALUE (Path))* FROM <FromClause> [WHERE <WhereClause>]?
    Eg. SELECT FIRST_VALUE (status), FIRST_VALUE (temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
    Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>

68、LAST_VALUE
    LAST_VALUE 函数返回所选时间序列的最后一个点值(一个或多个)。

    SELECT LAST_VALUE (Path) (COMMA LAST_VALUE (Path))* FROM <FromClause> [WHERE <WhereClause>]?
    Eg. SELECT LAST_VALUE (status), LAST_VALUE (temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
    Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>

69、MAX_TIME
    MAX_TIME 函数返回所选时间序列(一个或多个)的最大时间戳。结果是一个大于 0 的有符号 64 位整数。

    SELECT MAX_TIME (Path) (COMMA MAX_TIME (Path))* FROM <FromClause> [WHERE <WhereClause>]?
    Eg. SELECT MAX_TIME(status), MAX_TIME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
    Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>

70、MAX_VALUE
    MAX_VALUE 函数返回所选时间序列(一个或多个)的最大值(按字典顺序排列)。

    SELECT MAX_VALUE (Path) (COMMA MAX_VALUE (Path))* FROM <FromClause> [WHERE <WhereClause>]?
    Eg. SELECT MAX_VALUE(status), MAX_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
    Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>

71、EXTREME
    EXTREME 函数返回所选时间序列(一个或多个)的极值(按字典顺序排列)。极值:具有最大绝对值的值。如果正值和负值的最大绝对值相等,则返回正值。

    SELECT EXTREME (Path) (COMMA EXT (Path))* FROM <FromClause> [WHERE <WhereClause>]?
    Eg. SELECT EXTREME(status), EXTREME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
    Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>

72、AVG(Rename from MEAN at V0.9.0)
    AVG 函数返回指定时间段内所选时间序列的算术平均值。timeseries 必须是 int32、int64、float、double 类型,其他类型不计算。结果是一个双精度类型的数字。

    SELECT AVG (Path) (COMMA AVG (Path))* FROM <FromClause> [WHERE <WhereClause>]?
    Eg. SELECT AVG (temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
    Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>

73、MIN_TIME
    MIN_TIME 函数返回所选时间序列(一个或多个)的最小时间戳。结果是一个大于 0 的有符号 64 位整数。

    SELECT MIN_TIME (Path) (COMMA MIN_TIME (Path))*FROM <FromClause> [WHERE <WhereClause>]?
    Eg. SELECT MIN_TIME(status), MIN_TIME(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
    Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>

74、MIN_VALUE
    MIN_VALUE 函数返回所选时间序列(一个或多个)的最小值(按字典顺序排列)。

    SELECT MIN_VALUE (Path) (COMMA MIN_VALUE (Path))* FROM <FromClause> [WHERE <WhereClause>]?
    Eg. SELECT MIN_VALUE(status),MIN_VALUE(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
    Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>

75、NOW
    NOW 函数返回当前时间戳。该函数可以在数据操作语句中用于表示时间。结果是一个大于 0 的有符号 64 位整数。

    NOW()
    Eg. INSERT INTO root.ln.wf01.wt01(timestamp,status) VALUES(NOW(), false)
    Eg. DELETE FROM root.ln.wf01.wt01.status, root.ln.wf01.wt01.temperature WHERE time < NOW()
    Eg. SELECT * FROM root WHERE time < NOW()
    Eg. SELECT COUNT(temperature) FROM root.ln.wf01.wt01 WHERE time < NOW()

76、SUM
    SUM 函数返回指定时间段内所选时间序列(一个或多个)的总和。timeseries 必须是 int32、int64、float、double 类型,其他类型不计算。结果是一个双精度类型的数字。

    SELECT SUM(Path) (COMMA SUM(Path))* FROM <FromClause> [WHERE <WhereClause>]?
    Eg. SELECT SUM(temperature) FROM root.ln.wf01.wt01 WHERE root.ln.wf01.wt01.temperature < 24
    Note: the statement needs to satisfy this constraint: <PrefixPath> + <Path> = <Timeseries>

#TTL
IoTDB 支持存储级别的 TTL 设置,这意味着它能够自动定期删除旧数据。使用 TTL 的好处是希望您可以控制总磁盘空间使用情况并防止机器用尽磁盘。此外,随着文件总数的增加,查询性能可能会下降,并且随着文件的增多,内存使用量也会增加。及时删除此类文件有助于保持较高的查询性能水平并减少内存使用量。IoTDB 中的 TTL 操作由以下三个语句支持:

77、设置 TTL
    SET TTL TO StorageGroupName TTLTime
    Eg. SET TTL TO root.group1 3600000
    This example means that for data in root.group1, only that of the latest 1 hour will remain, the
    older one is removed or made invisible. 
    Note: TTLTime should be millisecond timestamp. When TTL is set, insertions that fall
    out of TTL will be rejected.

78、取消设置 TTL
    UNSET TTL TO StorageGroupName
    Eg. UNSET TTL TO root.group1
    This example means that data of all time will be accepted in this group. 

79、查看 TTL
    SHOW ALL TTL
    SHOW TTL ON StorageGroupNames
    Eg.1 SHOW ALL TTL
    This example will show TTLs of all storage groups.
    Eg.2 SHOW TTL ON root.group1,root.group2,root.group3
    This example will show TTLs of the specified 3 groups.
    Notice: storage groups without TTL will show a "null"

注意:当您为某些存储组设置 TTL 时,TTL 外的数据会立即变得不可见,但由于数据文件可能同时包含过期数据和活动数据,或者数据文件可能正在被查询使用,因此物理删除的数据已过时。如果您在之前设置后立即增加或取消设置 TTL,则可能会再次看到一些以前不可见的数据,但物理删除的数据将永远丢失。也就是说,与delete语句不同的是,出于效率的考虑,数据删除的原子性并不能得到保证。因此,我们建议您一旦设置了 TTL,就不要更改它,或者至少不要频繁重置它,除非您确定要承受不可预测性。

80、删除分区(实验性)
    DELETE PARTITION StorageGroupName INT(COMMA INT)*
    Eg DELETE PARTITION root.sg1 0,1,2
    This example will delete the first 3 time partitions of storage group root.sg1.


取消查询
81、显示正在进行的查询列表
    SHOW QUERY PROCESSLIST

82、杀死查询
    KILL QUERY INT?
    E.g. KILL QUERY
    E.g. KILL QUERY 2

将系统设置为只读/可写
83、将 IoTDB 系统设置为只读或可写模式。
    IoTDB> SET SYSTEM TO READONLY
    IoTDB> SET SYSTEM TO WRITABLE

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

芯晖闲云

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值