I’m trying to extract the most recent value from a data set to use in a map query. The query runs by itself in the Explorer tab, but when I try to use the extracted value in a map I am getting type error: (expected [A] but found (field: string) => B)
.
Here is the query I got trying to follow the documentation for extracting scalar values
option task = {name: "Scale Data", every: 1s}
getValue = (b, me, f) => {
r = from(bucket: b)
|> range(start: -99d)
|> filter(fn: (r) => r["_measurement"] == me and r["_field"] == f)
|> group(columns: ["_field"])
|> first()
|> aggregateWindow(every: 1s, fn: last, createEmpty: false)
|> yield(name: "last")
|> findColumn(
fn: (key) => (key._field == f),
column: "_value"
)
return r
}
scalar = getValue(b: "test_bucket", me: "test_measurement", f: "test_field")
from(bucket: "DataBucket")
|> range(start: -1s)
|> filter(fn: (r) =>
(r["_field"] == "data"))
|> set(key: "_measurement", value: "scaledMeasurements")
|> map(fn: (r) =>
({r with _value: r._value * scalar}))
|> to(bucket: "ScaledDataBucket", fieldFn: (r) =>
({scaledData: r._value}))