简体   繁体   中英

Flux Query : iterate filter from a list

I search a way to filter by a loop/iterate from a list

is it possible?

The table tophdd contains 2 entries, but i can't filter these two entries with a regex.

tophdd = from(bucket: v.bucket)
|>range(start: v.timeRangeStart, stop: v.timeRangeStop)
|>filter(fn: (r) => r._measurement == "HDDID")
|>filter(fn: (r) => r.serial == "${Serial}")
|>filter(fn: (r) => r._field == "HDDID_IOPS")
|>highestMax(n:2,groupColumns: ["HDDID"])
|>keep(columns: ["HDDID" ])

|>from(bucket: v.bucket)
|>range(start: v.timeRangeStart, stop: v.timeRangeStop)
|>filter(fn: (r) => r._measurement == "HDDID")
|>filter(fn: (r) => r.serial == "${Serial}")
|>filter(fn: (r) => r._field == "HDDID_IOPS")
|>filter(fn: (r) => r.HDDID = =~ /"${tophdd}"/)
|>aggregateWindow(column: "_value", every: v.windowPeriod, fn: mean)

i search to filter like this:

filter(fn: (r) => r.HDDID = =~ /"${tophdd}"/)

Is it possible to filter from a list?

Many thanks,

Looks like you just had a duplicate equal sign ( = = ) there. Try to update the query as follows:

filter(fn: (r) => r.HDDID =~ /"${tophdd}"/)

See more details here .

You can extract column values using findColumn to an array and then usecontains function in the filter. Eg.

tophdd = from(bucket: v.bucket)
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> ...
  |> keep(columns: ["HDDID" ])
  |> findColumn(fn: (key) => true, column: "HDDID")

from(bucket: v.bucket)
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r._measurement == "HDDID")
  |> ...
  |> filter(fn: (r) => contains(set: tophdd, value: r.HDDID))
  |> aggregateWindow(column: "_value", every: v.windowPeriod, fn: mean)

Please note that the performance may be suboptimal as contains() is not a pushdown op.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM