diff --git a/docs/Documentation-CHN/UserGuide/5-Operation Manual/1-DDL (Data Definition Language).md b/docs/Documentation-CHN/UserGuide/5-Operation Manual/1-DDL (Data Definition Language).md index 42a1d3b985e..d0ae818db34 100644 --- a/docs/Documentation-CHN/UserGuide/5-Operation Manual/1-DDL (Data Definition Language).md +++ b/docs/Documentation-CHN/UserGuide/5-Operation Manual/1-DDL (Data Definition Language).md @@ -102,6 +102,43 @@ IoTDB > COUNT TIMESERIES root.ln.*.*.status IoTDB > COUNT TIMESERIES root.ln.wf01.wt01.status ``` +除此之外,还可以通过定义`LEVEL`来统计指定层级下的时间序列个数。这条语句可以用来统计每一个设备下的传感器数量,语法为:`COUNT TIMESERIES GROUP BY LEVEL=`。 + +例如有如下时间序列(可以使用`show timeseries`展示所有时间序列): + +
+ +那么Metadata Tree如下所示: + +
+ +可以看到,`root`被定义为`LEVEL=0`。那么当你输入如下语句时: + +``` +IoTDB > COUNT TIMESERIES root GROUP BY LEVEL=1 +IoTDB > COUNT TIMESERIES root.ln GROUP BY LEVEL=2 +IoTDB > COUNT TIMESERIES root.ln.wf01 GROUP BY LEVEL=2 +``` + +你将得到以下结果: +
+ +> 注意:时间序列的路径只是过滤条件,与level的定义无关。 + +### 统计节点数 +IoTDB支持使用`COUNT NODES LEVEL=`来统计当前Metadata树下指定层级的节点个数,这条语句可以用来统计设备数。例如: + +``` +IoTDB > COUNT NODES root LEVEL=2 +IoTDB > COUNT NODES root.ln LEVEL=2 +IoTDB > COUNT NODES root.ln.wf01 LEVEL=3 +``` + +对于上面提到的例子和Metadata Tree,你可以获得如下结果: +
+ +> 注意:时间序列的路径只是过滤条件,与level的定义无关。 + ### 删除时间序列 我们可以使用`DELETE TimeSeries `语句来删除我们之前创建的时间序列。SQL语句如下所示: ``` diff --git a/docs/Documentation-CHN/UserGuide/5-Operation Manual/4-SQL Reference.md b/docs/Documentation-CHN/UserGuide/5-Operation Manual/4-SQL Reference.md index 11c31873015..f45bf3517b0 100644 --- a/docs/Documentation-CHN/UserGuide/5-Operation Manual/4-SQL Reference.md +++ b/docs/Documentation-CHN/UserGuide/5-Operation Manual/4-SQL Reference.md @@ -215,7 +215,9 @@ FromClause : (COMMA )? WhereClause : [(AND | OR) ]* Condition : [(AND | OR) ]* Expression : [NOT | !]? | [NOT | !]? -TimeExpr : TIME PrecedenceEqualOperator +TimeExpr : TIME PrecedenceEqualOperator ( | ) +RelativeTimeDurationUnit = Integer ('Y'|'MO'|'W'|'D'|'H'|'M'|'S'|'MS'|'US'|'NS') +RelativeTime : (now() | ) [(+|-) RelativeTimeDurationUnit]+ SensorExpr : ( | ) PrecedenceEqualOperator 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 @@ -241,7 +243,9 @@ FromClause : WhereClause : [(AND | OR) ]* Condition : [(AND | OR) ]* Expression : [NOT | !]? | [NOT | !]? -TimeExpr : TIME PrecedenceEqualOperator +TimeExpr : TIME PrecedenceEqualOperator ( | ) +RelativeTimeDurationUnit = Integer ('Y'|'MO'|'W'|'D'|'H'|'M'|'S'|'MS'|'US'|'NS') +RelativeTime : (now() | ) [(+|-) RelativeTimeDurationUnit]+ SensorExpr : ( | ) PrecedenceEqualOperator GroupByClause : LPAREN (COMMA TimeValue)? COMMA (COMMA )* RPAREN TimeUnit : Integer @@ -295,7 +299,9 @@ FromClause : WhereClause : [(AND | OR) ]* Condition : [(AND | OR) ]* Expression: [NOT|!]? | [NOT|!]? -TimeExpr : TIME PrecedenceEqualOperator +TimeExpr : TIME PrecedenceEqualOperator ( | ) +RelativeTimeDurationUnit = Integer ('Y'|'MO'|'W'|'D'|'H'|'M'|'S'|'MS'|'US'|'NS') +RelativeTime : (now() | ) [(+|-) RelativeTimeDurationUnit]+ SensorExpr : (|) PrecedenceEqualOperator LIMITClause : [OFFSETClause]? N : NonNegativeInteger diff --git a/docs/Documentation/UserGuide/5-Operation Manual/1-DDL (Data Definition Language).md b/docs/Documentation/UserGuide/5-Operation Manual/1-DDL (Data Definition Language).md index 85b27ba6e69..59b90079ccf 100644 --- a/docs/Documentation/UserGuide/5-Operation Manual/1-DDL (Data Definition Language).md +++ b/docs/Documentation/UserGuide/5-Operation Manual/1-DDL (Data Definition Language).md @@ -91,7 +91,7 @@ The results are shown below respectly: It is worth noting that when the queried path does not exist, the system will return no timeseries. ### Count Timeseries -IoTDB are able to use `COUNT TIMESERIES` to count the amount of timeseries in the path. SQL statements are as follows: +IoTDB is able to use `COUNT TIMESERIES` to count the number of timeseries in the path. SQL statements are as follows: ``` IoTDB > COUNT TIMESERIES root IoTDB > COUNT TIMESERIES root.ln @@ -99,6 +99,42 @@ IoTDB > COUNT TIMESERIES root.ln.*.*.status 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 GROUP BY LEVEL=`. + +For example, if there are several timeseires (use `show timeseries` to show all timeseries): +
+ +Then the Metadata Tree will be as below: +
+ +As can be seen, `root` is considered as `LEVEL=0`. So when you enter statements such as: + +``` +IoTDB > COUNT TIMESERIES root GROUP BY LEVEL=1 +IoTDB > COUNT TIMESERIES root.ln GROUP BY LEVEL=2 +IoTDB > COUNT TIMESERIES root.ln.wf01 GROUP BY LEVEL=2 +``` + +You will get following results: + +
+ +> 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 LEVEL=` 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: +``` +IoTDB > COUNT NODES root LEVEL=2 +IoTDB > COUNT NODES root.ln LEVEL=2 +IoTDB > COUNT NODES root.ln.wf01 LEVEL=3 +``` + +As for the above mentioned example and Metadata tree, you can get following results: + +
+ +> 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 ` statement. diff --git a/docs/Documentation/UserGuide/5-Operation Manual/4-SQL Reference.md b/docs/Documentation/UserGuide/5-Operation Manual/4-SQL Reference.md index 24680a03968..88982f1de10 100644 --- a/docs/Documentation/UserGuide/5-Operation Manual/4-SQL Reference.md +++ b/docs/Documentation/UserGuide/5-Operation Manual/4-SQL Reference.md @@ -221,7 +221,9 @@ FromClause : (COMMA )? WhereClause : [(AND | OR) ]* Condition : [(AND | OR) ]* Expression : [NOT | !]? | [NOT | !]? -TimeExpr : TIME PrecedenceEqualOperator +TimeExpr : TIME PrecedenceEqualOperator ( | ) +RelativeTimeDurationUnit = Integer ('Y'|'MO'|'W'|'D'|'H'|'M'|'S'|'MS'|'US'|'NS') +RelativeTime : (now() | ) [(+|-) RelativeTimeDurationUnit]+ SensorExpr : ( | ) PrecedenceEqualOperator 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 @@ -247,7 +249,9 @@ FromClause : WhereClause : [(AND | OR) ]* Condition : [(AND | OR) ]* Expression : [NOT | !]? | [NOT | !]? -TimeExpr : TIME PrecedenceEqualOperator +TimeExpr : TIME PrecedenceEqualOperator ( | ) +RelativeTimeDurationUnit = Integer ('Y'|'MO'|'W'|'D'|'H'|'M'|'S'|'MS'|'US'|'NS') +RelativeTime : (now() | ) [(+|-) RelativeTimeDurationUnit]+ SensorExpr : ( | ) PrecedenceEqualOperator GroupByClause : LPAREN (COMMA TimeValue)? COMMA (COMMA )* RPAREN TimeUnit : Integer @@ -301,7 +305,9 @@ FromClause : WhereClause : [(AND | OR) ]* Condition : [(AND | OR) ]* Expression: [NOT|!]? | [NOT|!]? -TimeExpr : TIME PrecedenceEqualOperator +TimeExpr : TIME PrecedenceEqualOperator ( | ) +RelativeTimeDurationUnit = Integer ('Y'|'MO'|'W'|'D'|'H'|'M'|'S'|'MS'|'US'|'NS') +RelativeTime : (now() | ) [(+|-) RelativeTimeDurationUnit]+ SensorExpr : (|) PrecedenceEqualOperator LIMITClause : [OFFSETClause]? N : PositiveInteger diff --git a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java index ee7ded20484..47168a9574f 100644 --- a/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java +++ b/jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBStatement.java @@ -295,7 +295,7 @@ public class IoTDBStatement implements Statement { return true; } } else if (sqlToLowerCase.startsWith(COUNT_NODES_COMMAND_LOWERCASE)) { - String[] cmdSplit = sql.split("\\s+", 4); + String[] cmdSplit = sqlToLowerCase.split("\\s+", 4); if (!(cmdSplit.length == 4 && cmdSplit[3].startsWith("level"))) { throw new SQLException("Error format of \'COUNT NODES LEVEL=\'"); } else {