未验证 提交 4bdc1dd5 编写于 作者: L Liu Jicong 提交者: GitHub

Merge pull request #16070 from taosdata/docs/td-15880-2

docs: update 06-stream.md for stream-computing
......@@ -22,7 +22,7 @@ stream_options: {
## 示例一
企业电表的数据经常都是成百上千亿条的,那么想要将这些分散、凌乱的数据清洗或转换都需要比较长的时间,很难做到高效性和实时性,以下例子中,通过流计算可以将过去 12 小时电表电压大于 220V 的数据清洗掉,然后以小时为窗口整合并计算出每个窗口中电流的最大值,并将结果输出到指定的数据表中。
企业电表的数据经常都是成百上千亿条的,那么想要将这些分散、凌乱的数据清洗或转换都需要比较长的时间,很难做到高效性和实时性,以下例子中,通过流计算可以将电表电压大于 220V 的数据清洗掉,然后以 5 秒为窗口整合并计算出每个窗口中电流的最大值,最后将结果输出到指定的数据表中。
### 创建 DB 和原始数据表
......@@ -44,19 +44,19 @@ CREATE TABLE d1004 USING meters TAGS ("California.LosAngeles", 3);
### 创建流
```sql
create stream current_stream into current_stream_output_stb as select _wstart as start, _wend as end, max(current) as max_current from meters where voltage <= 220 and ts > now - 12h interval (1h);
create stream current_stream into current_stream_output_stb as select _wstart as start, _wend as end, max(current) as max_current from meters where voltage <= 220 interval (5s);
```
### 写入数据
```sql
insert into d1001 values(now-13h, 10.30000, 219, 0.31000);
insert into d1001 values(now-11h, 12.60000, 218, 0.33000);
insert into d1001 values(now-10h, 12.30000, 221, 0.31000);
insert into d1002 values(now-9h, 10.30000, 218, 0.25000);
insert into d1003 values(now-8h, 11.80000, 221, 0.28000);
insert into d1003 values(now-7h, 13.40000, 223, 0.29000);
insert into d1004 values(now-6h, 10.80000, 223, 0.29000);
insert into d1004 values(now-5h, 11.50000, 221, 0.35000);
insert into d1001 values("2018-10-03 14:38:05.000", 10.30000, 219, 0.31000);
insert into d1001 values("2018-10-03 14:38:15.000", 12.60000, 218, 0.33000);
insert into d1001 values("2018-10-03 14:38:16.800", 12.30000, 221, 0.31000);
insert into d1002 values("2018-10-03 14:38:16.650", 10.30000, 218, 0.25000);
insert into d1003 values("2018-10-03 14:38:05.500", 11.80000, 221, 0.28000);
insert into d1003 values("2018-10-03 14:38:16.600", 13.40000, 223, 0.29000);
insert into d1004 values("2018-10-03 14:38:05.000", 10.80000, 223, 0.29000);
insert into d1004 values("2018-10-03 14:38:06.500", 11.50000, 221, 0.35000);
```
### 查询以观查结果
......@@ -65,9 +65,9 @@ insert into d1004 values(now-5h, 11.50000, 221, 0.35000);
taos> select start, end, max_current from current_stream_output_stb;
start | end | max_current |
===========================================================================
2022-08-12 04:00:00.000 | 2022-08-12 05:00:00.000 | 12.60000 |
2022-08-12 06:00:00.000 | 2022-08-12 07:00:00.000 | 10.30000 |
Query OK, 2 rows in database (0.009580s)
2018-10-03 14:38:05.000 | 2018-10-03 14:38:10.000 | 10.30000 |
2018-10-03 14:38:15.000 | 2018-10-03 14:38:20.000 | 12.60000 |
Query OK, 2 rows in database (0.018762s)
```
## 示例二
......@@ -93,13 +93,13 @@ create stream power_stream into power_stream_output_stb as select ts, concat_ws(
taos> select ts, meter_location, active_power, reactive_power from power_stream_output_stb;
ts | meter_location | active_power | reactive_power |
===================================================================================================================
2022-08-12 11:25:32.579 | California.LosAngeles.d1003 | 2506.240411679 | 720.680274962 |
2022-08-12 12:25:32.586 | California.LosAngeles.d1003 | 2863.424274422 | 854.482390839 |
2022-08-12 13:25:32.594 | California.LosAngeles.d1004 | 2307.834596289 | 688.687331847 |
2022-08-12 14:25:32.601 | California.LosAngeles.d1004 | 2387.415754896 | 871.474763418 |
2022-08-12 10:25:32.566 | California.SanFrancisco.d1002 | 2175.595991997 | 555.520860397 |
2022-08-12 06:25:32.534 | California.SanFrancisco.d1001 | 2148.178871730 | 688.120784090 |
2022-08-12 08:25:32.546 | California.SanFrancisco.d1001 | 2598.589176205 | 890.081451418 |
2022-08-12 09:25:32.555 | California.SanFrancisco.d1001 | 2588.728381186 | 829.240910475 |
Query OK, 8 rows in database (0.013775s)
2018-10-03 14:38:05.000 | California.LosAngeles.d1004 | 2307.834596289 | 688.687331847 |
2018-10-03 14:38:06.500 | California.LosAngeles.d1004 | 2387.415754896 | 871.474763418 |
2018-10-03 14:38:05.500 | California.LosAngeles.d1003 | 2506.240411679 | 720.680274962 |
2018-10-03 14:38:16.600 | California.LosAngeles.d1003 | 2863.424274422 | 854.482390839 |
2018-10-03 14:38:05.000 | California.SanFrancisco.d1001 | 2148.178871730 | 688.120784090 |
2018-10-03 14:38:15.000 | California.SanFrancisco.d1001 | 2598.589176205 | 890.081451418 |
2018-10-03 14:38:16.800 | California.SanFrancisco.d1001 | 2588.728381186 | 829.240910475 |
2018-10-03 14:38:16.650 | California.SanFrancisco.d1002 | 2175.595991997 | 555.520860397 |
Query OK, 8 rows in database (0.014753s)
```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册