Using InfluxDB difference function

自古美人都是妖i 提交于 2020-06-01 04:36:47

问题


I have some measurement data in my influxdb database which I can query with:

select * from E_real_con
name: E_real_con
time value
---- -----
1537920001044785525 | 57160036.00
1538006401069651036 | 57227208.00
1538092800108297103 | 57294112.00
1538179200697333731 | 57366108.00

However, "value" is a cumulative value and I would like to get the delta/difference between two consecutive values.

I tried the following:

SELECT difference(last(value)) FROM E_real_con WHERE time >= now() - 7d GROUP BY time(1d) fill(null)

However, I get the following error message:

ERR: unsupported difference iterator type: *query.stringInterruptIterator

I would be happy to get some hints and feedback how to solve my issue.

I am using influxdb 1.6.1

Thanks a lot! Christoph


回答1:


I found the solution. The following two mistakes had to be corrected:

1) The values in the measurement were of type "string" and not "float". As the data was coming from nodered, I cleared the database and used parseFloat() in nodered before writing the data to influxdb. BTW: you can check the datatype of your measurement field by:

SHOW FIELD KEYS FROM E_real_con

2) It seems that the query command requires a "where"

This works:

SELECT difference(last(value)) FROM E_real_del WHERE time >= now() - 7d GROUP BY time(1d)

whereas:

SELECT difference(last(value)) FROM E_real_del GROUP BY time(1d)

does not work.

I hope this might help someone else.




回答2:


2) It seems that the query command requires a "where"

It's even more restricted than that. It requires a where with a minimum timestamp.

For example, the following gives me no result:

select difference(last(value)) from WaterConsumption_Total where time < now() - 1d group by time(1d) fill(previous)

While this does:

select difference(last(value)) from WaterConsumption_Total where time > '2019-08-23T00:00:00Z' group by time(1d) fill(previous)

This effectively makes it impossible to use such a query as a continuous query.



来源:https://stackoverflow.com/questions/52566289/using-influxdb-difference-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!