acidburn23
acidburn23

Reputation: 200

InfluxDB Variable from Query return calculated numbers

I want to use InfluxDB variable as a query. For the query I will be setting 3 variables:

start=100
end=200
step=25

The query should return the list of values - 100, 125, 150, 175, 200 and be available for that variable. How should I write the query to achieve this as the result. I will not be reading from any buckets or database and this is pure mathematical number list generation.

I know I could use CSV or Map type of variables but I would then have to manually calculate the list of numbers and update it vs if I have a query I can just change the start/end/step value and the new list would automatically get generated.

I'm stuck because Influx query doesn't provide a do-while or loop statement. If any other approach helps in achieving this result?

Upvotes: 0

Views: 480

Answers (1)

acidburn23
acidburn23

Reputation: 200

Found a not-so-clean solution, but this gets the job done for now.

import "generate"
start = 100
end = 200
step = 25
num = ((end-start)/step)+1
generate.from(
    count: num,
    fn: (n) => (start + step*n),
    start: 2021-01-01T00:00:00Z,
    stop: 2021-01-02T00:00:00Z,
)
|> toString()

Upvotes: 0

Related Questions