0

I 6 hour try convert influxQL to FLUX query. Any can do it ?

CREATE CONTINUOUS QUERY trade_to_candles_60 ON mydb 
RESAMPLE EVERY 10s FOR 10m 
BEGIN SELECT first(price) AS open, last(price) AS close, max(price) AS high, min(price) AS low, sum(amount) AS volume INTO 
candles_1m FROM trades WHERE 
GROUP BY time(1m), pair, exchange END
padavan
  • 714
  • 8
  • 22

1 Answers1

0

Following the sample provided by influxdata in their documentation (here), I would split this contiuous query into four flux tasks like this:

import "experimental"

options task = {
  name: "trade_to_candles_60_open",
  every: 10s
}

from(bucket: "mydb/")
  |> range(start: experimental.subDuration(d: 10m, from: now()))
  |> filter(fn: (r) =>
    r._measurement == "trades" and
    r._field == "price"
  )
  |> group(columns: ["pair","exchange"])
  |> aggregateWindow(every: 1m, fn: first)
  |> set(key: "_field", as: "open")
  |> to(bucket: "mydb/candles_1m")

I personnally think that it's not serious that influxdata doesn't provide any CQ to flux task converter. I try to migrate from 1.8 to 2.0 but it's a nightmare : no way to test flux task in 1.8, no way to use CQ in 2.0 to ease migration. Every CQ has to be manually rewritten in flux task and I've hundreds of CQ...

Dharman
  • 30,962
  • 25
  • 85
  • 135