Please, consider this set of data separated in 3 groups to reflect the 3 different groups of time
_measurement _time _field _value tag
test 2021-01-01T00:00:00Z fld 1 a
test 2021-01-01T00:00:00Z fld 1 b
test 2021-01-01T00:00:00Z fld 1 c
test 2021-01-01T00:00:00Z fld 1 d
test 2021-01-01T00:00:00Z fld 1 e
test 2021-01-01T00:00:00Z fld 1 f
Next time, tag elements c and e are removed ; tag elements g, h and i are added:
_measurement _time _field _value tag
test 2021-01-02T00:00:00Z fld 1 a
test 2021-01-02T00:00:00Z fld 1 b
test 2021-01-02T00:00:00Z fld 1 d
test 2021-01-02T00:00:00Z fld 1 f
test 2021-01-02T00:00:00Z fld 1 g
test 2021-01-02T00:00:00Z fld 1 h
test 2021-01-02T00:00:00Z fld 1 i
Next time, tag elements d, g and h are removed ; tag element j is added.
_measurement _time _field _value tag
test 2021-01-03T00:00:00Z fld 1 a
test 2021-01-03T00:00:00Z fld 1 b
test 2021-01-03T00:00:00Z fld 1 f
test 2021-01-03T00:00:00Z fld 1 i
test 2021-01-03T00:00:00Z fld 1 j
Now, I would like to find the right query to display the difference in tags between consecutive sets of times like this:
Time Tag_elmt_total Tag_elmt_removed Tag_elmt_added
2021-01-01T00:00:00Z 6 - -
2021-01-02T00:00:00Z 7 2 3
2021-01-03T00:00:00Z 5 3 1
I figured out how to count the total number of “tag” elements for each time, but I am not sure how to calculate the number of removed and added tag elements between each groups of time to produce a table like the one above…
from(bucket: "myBucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == "test" and r._field == "fld")
|> group(columns:["_time"])
|> sum()
|> group()
Thank you for any insight…