Could someone help me with migrating InfluxQL query to Flux? Please :)

InfluxQL query:

SELECT
run_id as “Run ID”,
min(timestamp_sec) as “Test started”,
(max(timestamp_millis)-min(timestamp_millis))/1000 as “Duration”,
max(startedThreads) as “Started threads”,
concat(‘Dashboard’) as “Link”
from jmresults_statistic
GROUP BY run_id,profile_name
ORDER BY run_id DESC
LIMIT 50

Hello @11114,
You bet!
The concat portion of your InfluxQL query confuses. Can you share the InfluxQL docs for that function? I can’t seem to find it

data = from(bucket: "mybucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "jmresults_statistic")
  |> group(columns: ["run_id", "profile_name"], mode:"by")
  |> sort(columns: ["run_id"], desc: true)
  |> limit(n:50) 

run_id = data 
  |> filter(fn: (r) => r["_field"] == "run_id")
  |> yield(name: "Run ID") 


timestamp_sec = data 
  |> filter(fn: (r) => r["_field"] == "timestamp_sec")
  |> min() 
  |> yield(name: "Test started")

timestamp_sec_min = timestamp_sec
  |> findRecord(fn: (key) => true, idx: 0)

timestamp_millis = data 
  |> filter(fn: (r) =>  r["_field"] == "timestamp_millis")
  |> max() 
  |> map(fn: (r) => ({ r with _value: (r._value - timestamp_sec_min._value)/1000}))
  |> yield(name: "Duration") 

started_threads = data 
  |> filter(fn: (r) =>  r["_field"] == "startedThreads")
  |> yield(name: "Started Threads") 

The last part is I’m unsure if whether the group, sort, and limit function should be applied for each subsequent variable/query. I included it at the top to limit your response to make the query faster, but I’m not confident it’ll yield the same results. It depends on the shape of your data. However, I hope this acts as a good starting point for you.

1 Like