Hello @juliopereirab,
You can now perform full or outer joins with the following function:
You query would look like this:
import "array"
import "join"
data =
array.from(
rows: [
{_time: 2022-01-01T00:00:00Z, Price: 20, Bookmaker: "Bookie1"},
{_time: 2022-02-01T00:00:00Z, Price: 18, Bookmaker: "Bookie2"},
{_time: 2022-03-01T00:00:00Z, Price: 21, Bookmaker: "Bookie1"},
{_time: 2022-04-01T00:00:00Z, Price: 20, Bookmaker: "Bookie2"},
],
)
data
|> pivot(rowKey:["_time"], columnKey: ["Bookmaker"], valueColumn: "Price")
|> fill(column: "1", usePrevious: true)
|> fill(column: "2", usePrevious: true)
|> yield(name: "solution before joins")
left = data
|> filter(fn: (r) => r.Bookmaker == "Bookie1")
right = data
|> filter(fn: (r) => r.Bookmaker == "Bookie2")
join.full(
left: left,
right: right,
on: (l, r) => l._time == r._time,
as: (l, r) => {
time = if exists l._time then l._time else r._time
return {_time: time, Bookie1: l.Price, Bookie2: r.Price}
},
)
|> fill(column: "Bookie1", usePrevious: true)
|> fill(column: "Bookie2", usePrevious: true)
|> yield(name: "solution after joins")