Add new Tag into Task before write into a new bucket?

Hi,

I created a Task which write the result of a query into another bucket. Is it possible to add some new Tags to the query result before I write in to the new destination?

Here my task Script:

from(bucket: “pv_daily”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “pv.AutarkyDay”)
|> filter(fn: (r) => r[“_field”] == “value”)
|> aggregateWindow(every: 1d, fn: max, createEmpty: false)
|> timeShift(duration: -1d)
|> yield(name: “max”)
|> to(bucket: “pv_fulltime”)

Thanks for help!

@Iceman Sure, you can use either set() or map(). If the tag is going to be the same for every point in the stream, I’d recommend set(). One thing to note is that, in order for the new column to be written as a tag, you need to add it to the group key. Also, you don’t need a yield() here. It will just unncessarily double the number of points you send in the the write request.

from(bucket: “pv_daily”)
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r[“_measurement”] == “pv.AutarkyDay”)
    |> filter(fn: (r) => r[“_field”] == “value”)
    |> aggregateWindow(every: 1d, fn: max, createEmpty: false)
    |> timeShift(duration: -1d)
    |> set(key: "tag-name", value: "tag-value")
    |> group(columns: ["_time", "_value"], mode: "except")
    |> to(bucket: “pv_fulltime”)

You you need to set the tag conditionally per row, you’ll need to use map(). If that’s what you need to do, let me know and I can give you an example.