Skip to content

Commit

Permalink
docs: add a downsampling example (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
yinbo3 authored Sep 24, 2024
1 parent 41d2828 commit 416e26a
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 8 deletions.
6 changes: 4 additions & 2 deletions dir.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
- title_en: Arrow Flight SQL
title_cn: Arrow Flight SQL
path: development-guide/arrow-flight-sql
- title_en: Downsampling
title_cn: 时间窗口查询
path: development-guide/high-performance-writing
- title_en: High-performance writing
title_cn: 高性能写入
path: development-guide/high-performance-writing
Expand Down Expand Up @@ -171,7 +174,6 @@
path: sql-reference/statements/trim
- title_en: Functions
title_cn: 函数
path: sql-reference/sql-functions
collapsed: true
children:
- title_en: Aggregation
Expand Down Expand Up @@ -225,7 +227,7 @@
title_cn: 快速开始
path: key-value-data-model/quick-start
- title_en: Redis Compatibility
title_cn: Redis兼容性
title_cn: Redis 兼容性
path: key-value-data-model/redis-compatibility

- title_en: Operation Guide
Expand Down
Empty file.
1 change: 0 additions & 1 deletion en_US/sql-reference/sql-functions.md

This file was deleted.

4 changes: 1 addition & 3 deletions zh_CN/admin/system-monitor-grafana.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ Prometheus 启动完成后,将会定时从 Datalayers 服务定时拉取指标
如果你还未安装 Grafana,请至 <a href="https://grafana.com/grafana/download?pg=get&plcmt=selfmanaged-box1-cta1" target="_blank">Grafana 官网下载页</a>下载并安装。
下载时请注意:**目前 Datalayers 支持 Grafana >=9.2.5 版本。**
你也可以通过 Docker 快速启动 Grafana 实例:
``` bash
Expand All @@ -76,4 +74,4 @@ docker run --name my-grafana --network host grafana/grafana

### 添加指标面板

添加 Prometheus 数据源后,可在 `Grafana - Dashboards` 手动添加指标面板,或<a href="https://github.com/datalayers-io/datalayers-with-grafana/blob/main/grafana/dashboard-imported.json" download="datalayers_dashboard-imported.json">点击下载</a> json 文件快速导入我们提供的模版。
添加 Prometheus 数据源后,可在 `Grafana - Dashboards` 手动添加指标面板,或<a href="https://github.com/datalayers-io/datalayers-with-grafana/blob/main/grafana/dashboard-imported.json" download="datalayers_dashboard-imported.json">点击下载</a> json 文件快速导入我们提供的模版。
51 changes: 51 additions & 0 deletions zh_CN/development-guide/downsampling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 聚合查询

在时序数据库中,降采样与聚合运算是较为常用的应用场景。通过降采样/抽稀减少数据点来降低数据点,以此减少计算、传输的负担,适用于长时间段的数据分析。而聚合计算则通过将多个数据点合并为一个值(如平均值、最大值或最小值)来提取趋势。两者结合可以有效提高查询性能,减少数据处理时间,同时保留重要的趋势信息,适用于工业IoT、监控和数据可视化等场景。

## 按时间窗口查询
Datalayers 支持按时间窗口进行聚合查询。
典型应用场景:传感器每秒上报数据,如我们展示该传感器数据最近一天或者一个月的变化趋势时,如果以秒为单位进行展示,则会带来以下一些问题:
* 数据传输量大
* 客户端计算量大且复杂
* 不利于图形展示、观察(点位过于密集)

按时间窗口对数据进行切割、聚合运行特别适用于此类场景。

### 示例
Table schema 如下:
```sql
CREATE TABLE sensor_info (
ts TIMESTAMP(9) NOT NULL DEFAULT CURRENT_TIMESTAMP,
sn STRING,
speed DOUBLE,
temperature DOUBLE,
timestamp KEY (ts))
PARTITION BY HASH(sn) PARTITIONS 8
ENGINE=TimeSeries
with (ttl='10d');CREATE TABLE sensor_info (
ts TIMESTAMP(9) NOT NULL DEFAULT CURRENT_TIMESTAMP,
sn STRING,
speed DOUBLE,
temperature DOUBLE,
timestamp KEY (ts))
PARTITION BY HASH(sn) PARTITIONS 8
ENGINE=TimeSeries
with (ttl='10d');
```

假设数据采集频率为 `1Hz`,在数据展示时我们希望查询 `sn = 1` 并且以 1分钟 的区间对数据进行聚合(获取一分钟以内 temperature 的平均值 ),则可使用时间函数对数据进行切割、云计算。SQL 语句如下:

```
SELECT date_bin('1 minutes', ts) as timepoint, avg(temperature) as temp from sensor_info where sn = 1 group by timepoint;
```

假设数据采集频率为 `1Hz`,在数据展示时我们希望查询 `sn = 1` 并且以 1天 的区间对数据进行聚合(获取一天以内 temperature 的最大值 ),则可使用时间函数对数据进行切割、云计算。SQL 语句如下:

```
SELECT date_bin('1 day', ts) as timepoint, max(temperature) as temp from sensor_info where sn = 1 group by timepoint;
```

更多函数说明:
* [聚合函数](../sql-reference/aggregation.md)
* [时间与日期函数](../sql-reference/date.md)
* [数据函数](../sql-reference/math.md)
1 change: 0 additions & 1 deletion zh_CN/sql-reference/sql-functions.md

This file was deleted.

5 changes: 4 additions & 1 deletion zh_CN/sql-reference/statements/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ SELECT j FROM table_name WHERE i=3;
SELECT i, sum(j) FROM table_name GROUP BY i;
```

相关函数参数:[函数](../sql-functions.md)
更多函数说明:
* [聚合函数](../aggregation.md)
* [时间与日期函数](../date.md)
* [数据函数](../math.md)

0 comments on commit 416e26a

Please sign in to comment.