Skip to content

update gap_fill #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions zh_CN/development-guide/downsampling.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ CREATE TABLE sensor_info (
with (ttl='10d');
```

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

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

```sql
SELECT date_bin('1 day', ts) as timepoint, max(temperature) as temp from sensor_info where sn = 1 group by timepoint;
Expand Down
12 changes: 12 additions & 0 deletions zh_CN/sql-reference/gap_fill.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ GROUP BY window

特别注意,如果 SQL 语句中包含时间戳列之外的分组列,那么插值会针对每个分组单独执行。这是考虑到不同分组的数据可能没有显著的关联,如果允许跨分组插值,可能得到异常点(Outlier)。

## date_bin、date_bin_gapfill 函数的起始时间

默认情况下,`date_bin` 和 `date_bin_gapfill` 的起始时间对齐参数 `origin` 是 ​UTC 时区的 1970-01-01T00:00:00​(Unix Epoch)。因此,如果函数中未显式指定 `origin`,窗口会从 ​UTC 时间的 0 点​ 开始对齐,而非本地时区的 0 点。

若数据时间戳为 2024-01-16T10:40:00+08:00(东八区),`date_bin('1 day', time)` 会将其对齐到 ​UTC 的 0 点​(即东八区的早上 8 点),而非东八区本地 0 点。
若需从北京时间 0 点对齐,需显式指定 `origin` 如下:

``` sql
date_bin('1 day', time, '2024-01-01T00:00:00+08:00')
```


## 其他注意事项

- `date_bin_gapfill` 只能作为投影列,且必须作为分组列。
Expand Down