Duplicate data with new host name

My downsampling task takes data from multiple hosts, and writes it to the downsampling-bucket associated with the same host names. All normal.
I want to create an exception, where data coming from a specific host-name, gets duplicated and written to the downsampling-bucket under two new host names.

Is there a way to duplicate/copying data while at the same time assigning it a new host name?
Or a way to integrate an if-else statement inside the to() function?

dummy code:

if r.host == "XYZ" then 
    // double up data and store it under two host names 
    |> to(bucket: "DOWNSAMPLE", host: "hostA")
    |> to(bucket: "DOWNSAMPLE", host: "hostB")
else 
    // all regular hosts
    |> to(bucket: "DOWNSAMPLE")
end

Hello @evsc,
I would do something like:

import "array"

data = array.from(rows: [{_time: 2020-01-01T00:00:00Z, _measurement: "test", _field: "test", _value: 1.0, host: "XYZ"},
{_time: 2020-01-02T00:00:00Z, _measurement: "test", _field: "test", _value: 1.0, host: "BOO"}])
 |> group(columns: ["host"], mode:"by")
 |> yield(name: "raw data")

data |> filter(fn: (r) => r.host == "XYZ")
     |> set(key: "host", value: "hostA")
     |> to(bucket: "downsample") 

data |> filter(fn: (r) => r.host == "XYZ")
     |> set(key: "host", value: "hostB")
     |> to(bucket: "downsample") 

data |> filter(fn: (r) => r.host != "XYZ")
     |> to(bucket: "downsample") 

hope that helps!

ps its helpful to incorporate a lot of yeild() statemnts along the way to make sure you’re getting your data in the shape you want before writing it.

Thank you.
Yes, that would work.
I was hoping for a more stream-lined version, because I have a few different transformations further down the line, which I’d now have to duplicate on all the three branches.