Skip to content

Commit 902b6f2

Browse files
authored
docs: document flow incremental read option (#2566)
Signed-off-by: discord9 <discord9@163.com>
1 parent 7a9cb6b commit 902b6f2

4 files changed

Lines changed: 108 additions & 0 deletions

File tree

docs/reference/sql/create.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,14 @@ CREATE [OR REPLACE] FLOW [ IF NOT EXISTS ] <flow-name>
499499
SINK TO <sink-table-name>
500500
[ EXPIRE AFTER <expr> ]
501501
[ COMMENT '<string>' ]
502+
[ WITH (<flow-option> = <value> [, ...]) ]
502503
AS
503504
<SQL>;
504505
```
505506

507+
The `WITH` clause specifies flow options.
508+
For example, the experimental `experimental_enable_incremental_read` option enables incremental source reads for eligible batching flows.
509+
506510
For `CREATE FLOW`, the query after `AS` can be a regular flow query or a TQL query. GreptimeDB also supports a strict TQL CTE form for cleaner flow definitions:
507511

508512
```sql

docs/user-guide/flow-computation/manage-flow.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ CREATE [ OR REPLACE ] FLOW [ IF NOT EXISTS ] <flow-name>
101101
SINK TO <sink-table-name>
102102
[ EXPIRE AFTER <expr> ]
103103
[ COMMENT '<string>' ]
104+
[ WITH (<flow-option> = <value> [, ...]) ]
104105
AS
105106
<SQL>;
106107
```
@@ -117,6 +118,8 @@ Conversely, when `IF NOT EXISTS` is specified, the command will have no effect i
117118
- `EXPIRE AFTER` is an optional interval to expire the data from the Flow engine.
118119
For more details, please refer to the [`EXPIRE AFTER`](#expire-after) part.
119120
- `COMMENT` is the description of the flow.
121+
- `WITH` specifies flow options.
122+
For example, the experimental `experimental_enable_incremental_read` option enables incremental source reads for eligible batching flows.
120123
- `SQL` part defines the continuous aggregation query.
121124
It defines the source tables provide data for the flow.
122125
Each flow can have multiple source tables.
@@ -158,6 +161,53 @@ For example, if the flow engine processes the aggregation at 10:00:00 and the `'
158161
any input data that arrive now with a time index older than 1 hour (before 09:00:00) will expire and be ignore.
159162
Only data timestamped from 09:00:00 onwards will be used in the aggregation and update to sink table.
160163

164+
### Experimental incremental source reads
165+
166+
:::warning Experimental feature
167+
The `experimental_enable_incremental_read` option is experimental.
168+
Its behavior and limitations may change in future releases.
169+
:::
170+
171+
For batching SQL flows whose source tables are append-only, you can enable incremental source reads:
172+
173+
```sql
174+
CREATE TABLE temp_sensor_data (
175+
sensor_id INT,
176+
loc STRING,
177+
temperature DOUBLE,
178+
ts TIMESTAMP TIME INDEX,
179+
PRIMARY KEY(sensor_id, loc)
180+
) WITH ('append_mode' = 'true');
181+
182+
CREATE FLOW temp_monitoring
183+
SINK TO temp_alerts
184+
WITH (experimental_enable_incremental_read = 'true')
185+
AS
186+
SELECT
187+
sensor_id,
188+
loc,
189+
max(temperature) AS max_temp,
190+
date_bin('10 seconds'::INTERVAL, ts) AS time_window
191+
FROM temp_sensor_data
192+
GROUP BY
193+
sensor_id,
194+
loc,
195+
time_window;
196+
```
197+
198+
When this option is enabled, Flow keeps per-region source sequence watermarks and attempts to read only newly appended source rows after the initial full snapshot.
199+
This is an execution optimization and does not change the query result.
200+
201+
The current limitations are:
202+
203+
- All source tables must be append-only tables created with `append_mode = 'true'`.
204+
Flow creation fails if any source table is not append-only.
205+
- The optimization only applies to batching SQL flows.
206+
TQL flows, unsupported aggregate shapes, and simple projection/filter flows do not use incremental source reads.
207+
- Source tables created with `ttl = 'instant'` currently use streaming mode and do not use this batching-mode option.
208+
- The first run still needs a full snapshot.
209+
Later runs may fall back to full snapshot or retry/repair when GreptimeDB cannot safely use incremental source reads.
210+
161211
### Write a SQL query
162212

163213
The `SQL` part of the flow is similar to a standard `SELECT` clause with a few differences. The syntax of the query is as follows:

i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/create.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,14 @@ CREATE [OR REPLACE] FLOW [ IF NOT EXISTS ] <flow-name>
503503
SINK TO <sink-table-name>
504504
[ EXPIRE AFTER <expr> ]
505505
[ COMMENT '<string>' ]
506+
[ WITH (<flow-option> = <value> [, ...]) ]
506507
AS
507508
<SQL>;
508509
```
509510

511+
`WITH` 子句用于指定 flow 选项。
512+
例如,实验性的 `experimental_enable_incremental_read` 选项可以为符合条件的 batching flow 启用增量 source 读取。
513+
510514
对于 `CREATE FLOW``AS` 后面的查询既可以是常规 Flow 查询,也可以是 TQL 查询。GreptimeDB 现在还支持一种严格受限的 TQL CTE 写法,用来让 Flow 定义更清晰:
511515

512516
```sql

i18n/zh/docusaurus-plugin-content-docs/current/user-guide/flow-computation/manage-flow.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ CREATE [ OR REPLACE ] FLOW [ IF NOT EXISTS ] <flow-name>
9090
SINK TO <sink-table-name>
9191
[ EXPIRE AFTER <expr> ]
9292
[ COMMENT '<string>' ]
93+
[ WITH (<flow-option> = <value> [, ...]) ]
9394
AS
9495
<SQL>;
9596
```
@@ -103,6 +104,8 @@ AS
103104
- `EXPIRE AFTER` 是一个可选的时间间隔,用于从 Flow 引擎中过期数据。
104105
有关更多详细信息,请参考 [`EXPIRE AFTER`](#expire-after) 部分。
105106
- `COMMENT` 是 flow 的描述。
107+
- `WITH` 指定 flow 选项。
108+
例如,实验性的 `experimental_enable_incremental_read` 选项可以为符合条件的 batching flow 启用增量读取 source 表。
106109
- `SQL` 部分定义了用于持续聚合的查询。
107110
它定义了为 flow 提供数据的源表。
108111
每个 flow 可以有多个源表。
@@ -144,6 +147,53 @@ source 表中超出指定过期时间的数据将不再被包含在 flow 的计
144147
当前时刻若输入数据的 Time Index 超过 1 小时(即早于 09:00:00),则会被判定为过期数据并被忽略。
145148
仅时间戳为 09:00:00 及之后的数据会参与聚合计算,并更新到目标表。
146149

150+
### 实验性的增量 source 读取
151+
152+
:::warning 实验性功能
153+
`experimental_enable_incremental_read` 选项是实验性的。
154+
它的行为和限制可能会在未来版本中变化。
155+
:::
156+
157+
对于 source 表为 append-only 表的 batching SQL flow,可以启用增量 source 读取:
158+
159+
```sql
160+
CREATE TABLE temp_sensor_data (
161+
sensor_id INT,
162+
loc STRING,
163+
temperature DOUBLE,
164+
ts TIMESTAMP TIME INDEX,
165+
PRIMARY KEY(sensor_id, loc)
166+
) WITH ('append_mode' = 'true');
167+
168+
CREATE FLOW temp_monitoring
169+
SINK TO temp_alerts
170+
WITH (experimental_enable_incremental_read = 'true')
171+
AS
172+
SELECT
173+
sensor_id,
174+
loc,
175+
max(temperature) AS max_temp,
176+
date_bin('10 seconds'::INTERVAL, ts) AS time_window
177+
FROM temp_sensor_data
178+
GROUP BY
179+
sensor_id,
180+
loc,
181+
time_window;
182+
```
183+
184+
启用该选项后,Flow 会维护每个 region 的 source sequence watermark,并在初始全量快照之后尝试只读取新追加的 source 行。
185+
这是一个执行优化,不会改变查询结果。
186+
187+
当前限制如下:
188+
189+
- 所有 source 表都必须是使用 `append_mode = 'true'` 创建的 append-only 表。
190+
如果任意 source 表不是 append-only 表,创建 Flow 会失败。
191+
- 该优化只适用于 batching SQL flow。
192+
TQL flow、不支持的聚合形态以及简单的 projection/filter flow 不会使用增量 source 读取。
193+
- 使用 `ttl = 'instant'` 创建的 source 表当前会使用 streaming 模式,不会使用这个 batching 模式选项。
194+
- 首次运行仍然需要全量快照。
195+
之后的运行在 GreptimeDB 无法安全使用增量 source 读取时,可能会回退到全量快照,或者进行重试/修复。
196+
147197
### 编写 SQL 查询
148198

149199
flow 的 `SQL` 部分类似于标准的 `SELECT` 子句,但有一些不同之处。查询的语法如下:

0 commit comments

Comments
 (0)