Skip to content

Commit

Permalink
Merge e42f496 into a5eba32
Browse files Browse the repository at this point in the history
  • Loading branch information
Jialin Qiao committed Apr 2, 2020
2 parents a5eba32 + e42f496 commit aa5e67b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
Expand Up @@ -244,36 +244,44 @@ The path after SELECT in GROUP BY statement must be aggregate function, otherwis

<center><img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/16079446/69116099-0b715300-0ac6-11ea-8074-84e04797b8c7.png"></center>

### Last timestamp Query
In scenarios when IoT devices updates data in a fast manner, users are more interested in the most recent record of IoT devices.
The LAST query is to return the most recent value of the given timeseries in a time-value pair format.
### Last point Query

The SQL statement is:
In scenarios when IoT devices updates data in a fast manner, users are more interested in the most recent point of IoT devices.

The Last point query is to return the most recent data point of the given timeseries in a three column format.

The SQL statement is defined as:

```
select last <Path> [COMMA <Path>]* from < PrefixPath > [COMMA < PrefixPath >]* <DISABLE ALIGN>
```
which means:

Query and return the data with the largest timestamp of timeseries prefixPath.path.
which means: Query and return the last data points of timeseries prefixPath.path.

The result will be returned in a three column table format.

In the following example, we queries the latest record of timeseries root.ln.wf01.wt01.status:
```
select last status from root.ln.wf01.wt01 disable align
| Time | Path | Value |
```
The result will be returned in a three column table format.

Example 1: get the last point of root.ln.wf01.wt01.speed:

```
> select last speed from root.ln.wf01.wt01
| Time | Path | Value |
| --- | ----------------------- | ----- |
| 5 | root.ln.wf01.wt01.status| 100 |
| 5 | root.ln.wf01.wt01.speed | 100 |
```
If the path root.ln.wf01.wt01 has multiple columns, for example id, status and temperature, the following case will return records of all the three measurements with the largest timestamp.

Example 2: get the last speed, status and temperature points of root.ln.wf01.wt01

```
select last id, status, temperature from root.ln.wf01.wt01 disable align
> select last speed, status, temperature from root.ln.wf01.wt01
| Time | Path | Value |
| --- | ---------------------------- | ----- |
| 5 | root.ln.wf01.wt01.id | 10 |
| 5 | root.ln.wf01.wt01.speed | 100 |
| 7 | root.ln.wf01.wt01.status | true |
| 9 | root.ln.wf01.wt01.temperature| 35.7 |
```
Expand Down
Expand Up @@ -273,35 +273,40 @@ GROUP BY的SELECT子句里的查询路径必须是聚合函数,否则系统将

<center><img style="width:100%; max-width:800px; max-height:600px; margin-left:auto; margin-right:auto; display:block;" src="https://user-images.githubusercontent.com/16079446/69116099-0b715300-0ac6-11ea-8074-84e04797b8c7.png"></center>

### 最近时间戳数据查询
### 最新数据查询

对应的SQL语句是
SQL语法

```
select last <Path> [COMMA <Path>]* from < PrefixPath > [COMMA < PrefixPath >]* <DISABLE ALIGN>
```
其含义是:

查询时间序列prefixPath.path中最近时间戳的数据
其含义是:查询时间序列prefixPath.path中最近时间戳的数据

结果集为三列的结构

下面的例子中查询时间序列root.ln.wf01.wt01.status最近时间戳的数据:
```
select last status from root.ln.wf01.wt01 disable align
| Time | Path | Value |
```
结果集为以下的形式返回:

示例 1:查询 root.ln.wf01.wt01.speed 的最新数据点

```
> select last speed from root.ln.wf01.wt01
| Time | Path | Value |
| --- | ----------------------- | ----- |
| 5 | root.ln.wf01.wt01.status| 100 |
| 5 | root.ln.wf01.wt01.speed | 100 |
```

假设root.ln.wf01.wt01中包含多列数据,如id, status, temperature,下面的例子将会把这几列数据在最近时间戳的记录同时返回:
示例 2:查询 root.ln.wf01.wt01 下 speed,status,temperature 的最新数据点

```
select last id, status, temperature from root.ln.wf01 disable align
> select last speed, status, temperature from root.ln.wf01
| Time | Path | Value |
| --- | ---------------------------- | ----- |
| 5 | root.ln.wf01.wt01.id | 10 |
| 5 | root.ln.wf01.wt01.speed | 100 |
| 7 | root.ln.wf01.wt01.status | true |
| 9 | root.ln.wf01.wt01.temperature| 35.7 |
```
Expand Down

0 comments on commit aa5e67b

Please sign in to comment.