range() 函数
range() 根据时间范围过滤行。
输入数据必须具有一个类型为时间的 _time 列。
在 _time 中具有空值的行会被过滤。range() 会添加一个值为 start 的 _start 列和一个值为 stop 的 _stop 列。_start 和 _stop 列会被添加到组键中。
每个输入表的组键值会被修改以适应时间范围。
所有行都在时间范围之外的表会被完全过滤。
函数类型签名
(<-tables: stream[{C with _time: time}], start: A, ?stop: B) => stream[{C with _time: time, _stop: time, _start: time}]
有关更多信息,请参见 Function type signatures。
参数
开始
(必填) 包含在结果中的最早时间。
结果 包括 与指定开始时间匹配的 _time 值。 使用相对持续时间、绝对时间或整数(以秒为单位的Unix时间戳)。 例如, -1h、 2019-08-28T22:00:00Z 或 1567029600。 持续时间相对于 now()。
停止
最新包含在结果中的时间。默认值是 now()。
结果 排除 与指定停止时间匹配的 _time 值的行。 使用相对持续时间、绝对时间或整数(以秒为单位的Unix时间戳)。 例如, -1h、 2019-08-28T22:00:00Z,或 1567029600。 持续时间相对于 now()。
表格
输入数据。默认是管道转发数据 (<-).
示例
查询与现在相关的时间范围
from(bucket: "example-bucket")
|> range(start: -12h)
查询绝对时间范围
from(bucket: "example-bucket")
|> range(start: 2021-05-22T23:30:00Z, stop: 2021-05-23T00:00:00Z)
使用Unix时间戳查询绝对时间范围
from(bucket: "example-bucket")
|> range(start: 1621726200, stop: 1621728000)