-
Notifications
You must be signed in to change notification settings - Fork 9
Description
depending on your situation, you can use if, then, else, or dictionaries for this. here is an example with dictionaries:
import "array"
import "dict"
d = ["field1": 10.0, "field2":20.0]
array.from(rows: [{_time: 2020-01-01T00:00:00Z, _field: "field1", _value: 1.0},
{_time: 2020-01-02T00:00:00Z, _field: "field2",_value: 1.0}])
|> map(fn: (r) => ({r with _value: r._value * dict.get(dict: d, key: r._field, default: 0.0)}))
here is the same thing but using conditional logic:
import "array"
array.from(rows: [{_time: 2020-01-01T00:00:00Z, _field: "field1", _value: 1.0},
{_time: 2020-01-02T00:00:00Z, _field: "field2",_value: 1.0}])
|> map(fn: (r) => ({r with _value: if r._field == "field1"
then r._value* 10.0
else
if r._field == "field2"
then r._value * 20.0
else 0.0}))