R does not work in join.time()

Dears

When I use left join, I find right does not work in join.time() function.

  • left as below, which filed is Him
  • rightas below, which filed is Temp
  • when i try to join the values into a table on time, value of temp, the right, cant yield out.When i print out r._filed to check, i found what printed was “Him”, which is value of l.filed.

code i used as below:

import "join"

raw = 
from(bucket: "bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "measurement")
  |> keep(columns: ["_time", "_field", "_value"])
//   |> yield(name: "sort")

left = raw
  |> filter(fn: (r) => r["_field"] == "Him")

right = raw
  |> filter(fn: (r) => r["_field"] == "Temp")

join.time(method: "left", left: left, right: right, as: (l, r) => ({l with him: r._value, him_field: r._field}))
  |> yield(name: "sort")

could you tell me what happend?

@Leo I think it’s because your fields have different keys, therefore the group keys of your two streams are different. Try ungrouping the raw stream so that the group keys match before the join.

import "join"

raw =
    from(bucket: "bucket")
        |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
        |> filter(fn: (r) => r["_measurement"] == "measurement")
        |> keep(columns: ["_time", "_field", "_value"])
        |> group()

left =
    raw
        |> filter(fn: (r) => r["_field"] == "Him")

right =
    raw
        |> filter(fn: (r) => r["_field"] == "Temp")

join.time(method: "left", left: left, right: right, as: (l, r) => ({l with him: r._value, him_field: r._field}))
    |> yield(name: "sort")

However, looking at your query, I don’t think you need a join. I avoid joins whenever I can because they’re complicated and they aren’t very performant. In this case, I think pivoting on time will give you the results you’re looking for:

from(bucket: "bucket")
    |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r["_measurement"] == "measurement")
    |> keep(columns: ["_time", "_field", "_value"])
    |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")

pivot does work better.thank you very much. :blush: