我希望具有GROUP BY time intervals and fill(previous)
的子查询的行为与所得数据集相同。但是针对子查询的查询返回意外结果。
环境
InfluxDB v1.6.3
发生了什么
这是一个示例数据集:
# DDL
CREATE DATABASE myapp
# DML
# CONTEXT-DATABASE: myapp
reqcnt,endpoint=a value=1 1563361000000000000
reqcnt,endpoint=b value=1 1563361000000000000
reqcnt,endpoint=a value=2 1563361005000000000
reqcnt,endpoint=b value=2 1563361005000000000
reqcnt,endpoint=a value=3 1563361010000000000
reqcnt,endpoint=b value=3 1563361010000000000
您可以通过执行以下操作导入以上数据:
$ influx -import /path/to/dataset -precision ns
数据很简单:每个端点三个值,每5秒测量一次。但是因为我想要一个具有每秒值的数据集,所以我做了一个子查询,用先前的值填充缺失的值:
> SELECT LAST(value) AS lv FROM reqcnt WHERE time >= 1563361000000000000 AND time <= 1563361010000000000 GROUP BY time(1s), endpoint fill(previous)
name: reqcnt
tags: endpoint=a
time lv
---- --
1563361000000000000 1
1563361001000000000 1
1563361002000000000 1
1563361003000000000 1
1563361004000000000 1
1563361005000000000 2
1563361006000000000 2
1563361007000000000 2
1563361008000000000 2
1563361009000000000 2
1563361010000000000 3
name: reqcnt
tags: endpoint=b
time lv
---- --
1563361000000000000 1
1563361001000000000 1
1563361002000000000 1
1563361003000000000 1
1563361004000000000 1
1563361005000000000 2
1563361006000000000 2
1563361007000000000 2
1563361008000000000 2
1563361009000000000 2
1563361010000000000 3
到目前为止,一切都很好。现在,我想总结一下端点:
> SELECT SUM(value) FROM (SELECT LAST(value) AS value FROM reqcnt WHERE time >= 1563361000000000000 AND time <= 1563361010000000000 GROUP BY time(1s), endpoint fill(previous)) WHERE time >= 1563361000000000000 AND time <= 1563361010000000000 GROUP BY time(1s)
name: reqcnt
time sum
---- ---
1563361000000000000 1
1563361001000000000 1
1563361002000000000 1
1563361003000000000 1
1563361004000000000 1
1563361005000000000 1
1563361006000000000 1
1563361007000000000 1
1563361008000000000 1
1563361009000000000 1
1563361010000000000 1
1563361000000000000 1
1563361001000000000 1
1563361002000000000 1
1563361003000000000 1
1563361004000000000 1
1563361005000000000 1
1563361006000000000 1
1563361007000000000 1
1563361008000000000 1
1563361009000000000 1
1563361010000000000 1
1563361005000000000 2
1563361006000000000 2
1563361007000000000 2
1563361008000000000 2
1563361009000000000 2
1563361010000000000 2
1563361005000000000 2
1563361006000000000 2
1563361007000000000 2
1563361008000000000 2
1563361009000000000 2
1563361010000000000 8
为什么结果包含相同时间戳的多个值?当我将11加11时为什么是34个值?
我期望的
> SELECT SUM(value) FROM (SELECT LAST(value) AS value FROM reqcnt WHERE time >= 1563361000000000000 AND time <= 1563361010000000000 GROUP BY time(1s), endpoint fill(previous)) WHERE time >= 1563361000000000000 AND time <= 1563361010000000000 GROUP BY time(1s)
name: reqcnt
time sum
---- ---
1563361000000000000 2
1563361001000000000 2
1563361002000000000 2
1563361003000000000 2
1563361004000000000 2
1563361005000000000 2
1563361006000000000 4
1563361007000000000 4
1563361008000000000 4
1563361009000000000 4
1563361010000000000 6
创建每秒的数据集并对其进行查询将返回预期结果:
# DDL
CREATE DATABASE myapp
# DML
# CONTEXT-DATABASE: myapp
reqcnt2,endpoint=a value=1 1563361000000000000
reqcnt2,endpoint=b value=1 1563361000000000000
reqcnt2,endpoint=a value=1 1563361001000000000
reqcnt2,endpoint=b value=1 1563361001000000000
reqcnt2,endpoint=a value=1 1563361002000000000
reqcnt2,endpoint=b value=1 1563361002000000000
reqcnt2,endpoint=a value=1 1563361003000000000
reqcnt2,endpoint=b value=1 1563361003000000000
reqcnt2,endpoint=a value=1 1563361004000000000
reqcnt2,endpoint=b value=1 1563361004000000000
reqcnt2,endpoint=a value=2 1563361005000000000
reqcnt2,endpoint=a value=2 1563361005000000000
reqcnt2,endpoint=b value=2 1563361006000000000
reqcnt2,endpoint=a value=2 1563361006000000000
reqcnt2,endpoint=b value=2 1563361007000000000
reqcnt2,endpoint=a value=2 1563361007000000000
reqcnt2,endpoint=b value=2 1563361008000000000
reqcnt2,endpoint=a value=2 1563361008000000000
reqcnt2,endpoint=b value=2 1563361009000000000
reqcnt2,endpoint=a value=2 1563361009000000000
reqcnt2,endpoint=a value=3 1563361010000000000
reqcnt2,endpoint=b value=3 1563361010000000000
导入以上内容并查询数据集将显示预期结果:
> SELECT SUM(value) FROM reqcnt2 WHERE time >= 1563361000000000000 AND time <= 1563361010000000000 GROUP BY time(1s)
name: reqcnt2
time sum
---- ---
1563361000000000000 2
1563361001000000000 2
1563361002000000000 2
1563361003000000000 2
1563361004000000000 2
1563361005000000000 2
1563361006000000000 4
1563361007000000000 4
1563361008000000000 4
1563361009000000000 4
1563361010000000000 6
那有什么区别?不应像查询实际数据集一样查询已填充的数据集?有没有适当的方法来查询此类子查询?