Hi,
I’m migrating from Influx 1 to influx 2 and trying to convert my continuous queries that aggregate/reduce the raw data using tasks and Flux.
I almost got it working, but in the last step to write the aggregated data back to a table, somehow one of the fields is not written back.
As probably the flux-query can also be improved I’ll describe the full use case:
The source table contains energy measurements from my solar panels. I have dashboards to look at all the details of the raw data, but after a week most of it is no longer interesting and can be compacted massively.
Basically the only thing to preserve is the Kwh meter data. This is just a simple increasing counter value that is sampled every 10 seconds.
What I want to do is to reduce the data with a daily task that writes into a new table the last meter reading of each day and also the total daily usage (= for each day: meter end value - start value).
So to do this for e.g. the last 7 days, the query I came up that seems to do the job is:
last = from(bucket: "testtelegraf")
|> range(start: -7d)
|> filter(fn: (r) => r["topic"] == "Import")
|> aggregateWindow(every: 1d, fn: last, createEmpty: false)
first = from(bucket: "testtelegraf")
|> range(start: -7d)
|> filter(fn: (r) => r["topic"] == "Import")
|> aggregateWindow(every: 1d, fn: first, createEmpty: false)
join(tables: {lastusage: last, firstusage: first}, on: ["_time", "_stop", "_start", "host", "_field", "_measurement","topic"])
|> map(fn: (r) => ({_value: r._value_lastusage - r._value_firstusage,
_meter_endvalue : r._value_lastusage,
_time: r._time
}))
|> set(key: "_measurement", value: "solar_daily")
|> set(key: "_field", value: "day_usage")
This output look exactly as I would like, having the “_time”, “day_usage” and “_meter_endvalue” columns nicely populated.
So, to write this to a daily table I have added this to the the above query:
|> to(bucket: "test_daily", org: "my-org", tagColumns: [""])
I now would expect the “test_daily” table to have the exact contents as the query results from above.
However, I’m missing the “meter_endvalue” column:
Why is the last column missing, what am I doing wrong here?