Skip to content

Commit e2dbe2e

Browse files
authored
docs: add sql lookup template doc (#3548)
Signed-off-by: Song Gao <disxiaofei@163.com>
1 parent 2366bd5 commit e2dbe2e

File tree

2 files changed

+78
-0
lines changed
  • docs
    • en_US/guide/sources/plugin
    • zh_CN/guide/sources/plugin

2 files changed

+78
-0
lines changed

docs/en_US/guide/sources/plugin/sql.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,42 @@ The cache configuration lies in the `sql.yaml`.
190190
* cache: bool value to indicate whether to enable cache.
191191
* cacheTtl: the time to live of the cache in seconds.
192192
* cacheMissingKey: whether to cache nil value for a key.
193+
194+
### Using TemplateSQL for Lookup Tables
195+
196+
In the SQL lookup configuration, it is also supported to use template SQL to customize the query for tables in the database:
197+
198+
```yaml
199+
sqlite_config:
200+
url: example.db
201+
templateSqlQueryCfg:
202+
templateSql: select * from t limit 100;
203+
```
204+
205+
Through this configuration, we can achieve the pre-calculation pushdown to the database level, as shown in the following example:
206+
207+
For the following rule:
208+
209+
```json
210+
{
211+
"id": "rule1",
212+
"sql": "SELECT demo.a, sqlookup.aid from demo inner join sqllookup on demo.b = sqllookup.bid",
213+
"actions": [
214+
{
215+
"log": {
216+
}
217+
}
218+
]
219+
}
220+
```
221+
222+
We can define the sqllookup with the following configuration:
223+
224+
```yaml
225+
sqlite3_lookup:
226+
url: example.db
227+
templateSqlQueryCfg:
228+
templateSql: select aid from t limit where b2 + 1 = {{.bid}};
229+
```
230+
231+
Through the above operation, we have pushed down the equivalence calculation where demo.b equals sqllookup.b2 + 1 to the database level during the SQL lookup query. For some equivalence calculation operations not supported by eKuiper, we can achieve them in this way.

docs/zh_CN/guide/sources/plugin/sql.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,42 @@ CREATE TABLE alertTable() WITH (DATASOURCE="tableName", CONF_KEY="sqlite_config"
185185
* cache: bool 值,表示是否启用缓存。
186186
* cacheTtl: 缓存的生存时间,单位是秒。
187187
* cacheMissingKey:是否对空值进行缓存。
188+
189+
### 使用 TemplateSQL 构造查询表的查询
190+
191+
在 sql lookup 配置中同样支持使用 template SQL 来自定义查询表在数据库中的查询:
192+
193+
```yaml
194+
sqlite_config:
195+
url: example.db
196+
templateSqlQueryCfg:
197+
templateSql: select * from t limit 100;
198+
```
199+
200+
通过这个配置,我们可以做到提前将一些计算下推到数据库中进行计算,如下例子:
201+
202+
对于如下规则:
203+
204+
```json
205+
{
206+
"id": "rule1",
207+
"sql": "SELECT demo.a, sqlookup.aid from demo inner join sqllookup on demo.b = sqllookup.bid",
208+
"actions": [
209+
{
210+
"log": {
211+
}
212+
}
213+
]
214+
}
215+
```
216+
217+
我们可以给 sqllookup 的定义如下配置:
218+
219+
```yaml
220+
sqlite3_lookup:
221+
url: example.db
222+
templateSqlQueryCfg:
223+
templateSql: select aid from t limit where b2 + 1 = {{.bid}};
224+
```
225+
226+
通过以上操作,我们将 sql lookup 查询时将 demo.b 等于 sqllookup.b2 +1 的等值计算下推到了数据库层面,对于一些 eKuiper 并不支持的等值计算操作,我们可以通过该方式实现。

0 commit comments

Comments
 (0)