0

我已经填充了数据库(Influxdb 2.0.7),所以它在一年中的每一天都包含 1 的值:

                    _time:time                  _value:int  
------------------------------  --------------------------  
2021-01-01T00:00:00.000000000Z                           1  
2021-01-02T00:00:00.000000000Z                           1  
2021-01-03T00:00:00.000000000Z                           1  
2021-01-04T00:00:00.000000000Z                           1  
2021-01-05T00:00:00.000000000Z                           1  
2021-01-06T00:00:00.000000000Z                           1  
...

现在我想查询数据库,以便对每个月的数据求和:

from(bucket: "my_bucket")
|> range(start: 1609459200, stop: 1640995200)
...
|> window(every: 1mo, offset: 0s, createEmpty: true)
|> sum()

这适用于0s 偏移量

Table: keys: [_start, _stop]
                   _start:time                      _stop:time                  _value:int  
------------------------------  ------------------------------  --------------------------  
2021-01-01T00:00:00.000000000Z  2021-02-01T00:00:00.000000000Z                          31  
Table: keys: [_start, _stop]
                   _start:time                      _stop:time                  _value:int  
------------------------------  ------------------------------  --------------------------  
2021-02-01T00:00:00.000000000Z  2021-03-01T00:00:00.000000000Z                          28  
Table: keys: [_start, _stop]
                   _start:time                      _stop:time                  _value:int  
------------------------------  ------------------------------  --------------------------  
2021-03-01T00:00:00.000000000Z  2021-04-01T00:00:00.000000000Z                          31  
Table: keys: [_start, _stop]
                   _start:time                      _stop:time                  _value:int  
------------------------------  ------------------------------  --------------------------  
2021-04-01T00:00:00.000000000Z  2021-05-01T00:00:00.000000000Z                          30 
...

但是,如果我将偏移量设置为负数(-7200s = 移动间隔到 +02:00 时区偏移量),它会返回奇怪的结果:

from(bucket: "my_bucket")
|> range(start: 1609459200, stop: 1640995200)
...
|> window(every: 1mo, offset: -7200s, createEmpty: true)
|> sum()

请注意,第 3 个月有 28 个项目而不是 31 个项目,并且窗口以 2021-03-28 而不是 2021-03-31T22:00:00 结束。

Table: keys: [_start, _stop]
                   _start:time                      _stop:time                  _value:int  
------------------------------  ------------------------------  --------------------------  
2021-01-01T00:00:00.000000000Z  2021-01-31T22:00:00.000000000Z                          31  
Table: keys: [_start, _stop]
                   _start:time                      _stop:time                  _value:int  
------------------------------  ------------------------------  --------------------------  
2021-01-31T22:00:00.000000000Z  2021-02-28T22:00:00.000000000Z                          28  
Table: keys: [_start, _stop]
                   _start:time                      _stop:time                  _value:int  
------------------------------  ------------------------------  --------------------------  
2021-02-28T22:00:00.000000000Z  2021-03-28T22:00:00.000000000Z                          28  
Table: keys: [_start, _stop]
                   _start:time                      _stop:time                  _value:int  
------------------------------  ------------------------------  --------------------------  
2021-03-31T22:00:00.000000000Z  2021-04-30T22:00:00.000000000Z                          30 

知道为什么 Flux 语言会返回这样的结果吗?还是我查询有问题?

4

0 回答 0