Join Tables issue

@mchacher This appears to be a bug in Flux. I can replicate the issue. The following query fails with an internal error:

table_raw = from(bucket: "noaa")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r["_measurement"] == "average_temperature")
    |> filter(fn: (r) => r["_field"] == "degrees")
    |> filter(fn: (r) => r["location"] == "santa_monica")

table_diff = table_raw
    |> difference(nonNegative: true, keepFirst: true)

join(
    tables: {tr: table_raw, td: table_diff},
    on: ["_time"]
)

However, the following query replaces the table_raw identifier in the table_diff definition with the full table_raw query and it works:

table_raw = from(bucket: "noaa")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r["_measurement"] == "average_temperature")
    |> filter(fn: (r) => r["_field"] == "degrees")
    |> filter(fn: (r) => r["location"] == "santa_monica")

table_diff = from(bucket: "noaa")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r["_measurement"] == "average_temperature")
    |> filter(fn: (r) => r["_field"] == "degrees")
    |> filter(fn: (r) => r["location"] == "santa_monica")
    |> difference(nonNegative: true, keepFirst: true)

join(
    tables: {tr: table_raw, td: table_diff},
    on: ["_time"]
)

It appears the Flux query planning is erring when trying two join two streams where one stream is used to define another. I’ve created an issue on the Flux repo to track the bug.

Thanks @scott. I was really stuck and since I am a beginner in Flux, I was not imaging one second facing a bug ;-).