influxdbinfluxdb-2

Full outer join complains about Return being a Function


I use the following Query to get a table from my InfluxDB

from(bucket: "external")
            |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
            |> filter(fn: (r) => r["_measurement"] == "Elektro")
            |> filter(fn: (r) => r["_field"] == "Verbrauch")
            |> filter(fn: (r) => contains(value: r["_zaehler"], set: strings.split(v: "IT A1,IT A2,IT A3,Carrier A,IT B1,IT B2,IT B3,Carrier B", t: ",")))
            |> group(columns: ["_time"])
            |> sum()
            |> map(fn: (r) => ({ r with _field: "Summe IT" }))
            |> group(columns: ["_time"])

This Query results in this table: resulting Table

Then with an full outer Join I try to join the table on itself (on the _time column):

join.full(
    left: (
        from(bucket: "external")
            |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
            |> filter(fn: (r) => r["_measurement"] == "Elektro")
            |> filter(fn: (r) => r["_field"] == "Verbrauch")
            |> filter(fn: (r) => contains(value: r["_zaehler"], set: strings.split(v: "IT A1,IT A2,IT A3,Carrier A,IT B1,IT B2,IT B3,Carrier B", t: ",")))
            |> group(columns: ["_time"])
            |> sum()
            |> map(fn: (r) => ({ r with _field: "Summe IT" }))
            |> group(columns: ["_time"])
            |> yield(name: "left")
    ),
    right:
        (
        from(bucket: "external")
            |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
            |> filter(fn: (r) => r["_measurement"] == "Elektro")
            |> filter(fn: (r) => r["_field"] == "Verbrauch")
            |> filter(fn: (r) => contains(value: r["_zaehler"], set: strings.split(v: "IT A1,IT A2,IT A3,Carrier A,IT B1,IT B2,IT B3,Carrier B", t: ",")))
            |> group(columns: ["_time"])
            |> sum()
            |> map(fn: (r) => ({ r with _field: "Summe IT" }))
            |> group(columns: ["_time"])
            |> yield(name: "right")
    ),
    on: (l, r) => (l._time == r._time),
    as: (l, r) => ({l}),
)

But this results in:

error @21:1-21:5: expected {
    A with
    full: (
        as: (l: B, r: C) => {l: B},
        left: stream[{D with _field: string}],
        on: (l: {E with _time: F}, r: {G with _time: H}) => bool,
        right: stream[{I with _field: string}],
    ) => stream[J],
} (record) but found (<-tables: K, ?method: string, ?on: [string]) => stream[L] (function)

The Format of the table will stay, in practise there will be different arrays for the ["_zaehler"] column.

I tried chaning the as part in my code to as: (l, r) => (l),. Also I tried removing the yield and replaced the last grouping with group(). Also changing the splitting of the string to just a regular Array didn't help.

None of it worked. I just can't figure out, why the join returns a function (this is at least how I interpreted the Error Message). My Input data seems fine to me, but looks like it's the problem.


Solution

  • I got it figured out myself. I actually forgot to import "join". Somehow forgetting the import results in this obscure Error Message. I hope other people running into the same Issue can be helped with this answer.