Reputation: 3631
I am trying to put an if condition in flux based on count. Following is the use case
//pseudo code
If (count > 0) the
//Show results from bucket A
else
//Show results from bucket B
I am unable to figure out what is right way of checking this, following is the actual flux
if from(bucket: "mytestbucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["entity_id"] == "main_power_availability")
|> filter(fn: (r) => r["_field"] == "value")
|> count() > 0
then
from(bucket: "mytestbucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["entity_id"] == "main_power_availability")
|> filter(fn: (r) => r["_field"] == "value")
|> aggregateWindow(every: 1m, fn: max, createEmpty: true)
|> fill(usePrevious: true)
|> yield(name: "max")
else
_lastvalue
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["entity_id"] == "main_power_availability")
|> filter(fn: (r) => r["_field"] == "value")
|> aggregateWindow(every: 5m, fn: max)
|> fill(usePrevious: true)
|> yield(name: "max")
But I get an error stream[A] is not Comparable
.
I have verified that count return correct result see below
The thing missing here is how to compare count integer value in condition, apparently it is comparing the returned table stream with integer value 0
and throwing this error. Have tried https://docs.influxdata.com/flux/v0/stdlib/universe/findcolumn/` without luck. I assume it would be a simple stuff yet hard to figure out from me from flux documentation.
Any help is appreciated!
Upvotes: 0
Views: 754
Reputation: 36
I would recommend to use a variable.
count = from(bucket: "mytestbucket")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["entity_id"] == "main_power_availability")
|> filter(fn: (r) => r["_field"] == "value")
|> count()
if count > 0 ...
Upvotes: 0