Odd behaviour with join.tables() and use of yield()

Hi,

I’m doing a simple join of two tables. The resulting “joined” table I want to display in a grafana table panel.
The problem is the join() function requires me to call yield() on the left consumption table first, otherwise nothing is returned from the join. But this causes an issue in that the grafana table panel shows both the previous left consumption and joined table in the UI as a dropdown. I only want to show the joined table. I remember in older versions of flux it was possible to do this without calling yield() on the prior tables used in the join - has something changed?

import "array"
import "join"

arr = [
    {tenant_id: "1", tenant_name: "OrgA", meter_id: "CCC_L01_M9_R514", bill_meter_id: "22"},
    {tenant_id: "1", tenant_name: "OrgA", meter_id: "CCC_L01_M1_R45099", bill_meter_id: "22"},
    {tenant_id: "2", tenant_name: "OrgB", meter_id: "CCC_L01_M14_R45099", bill_meter_id: "22"}
]

metadata = array.from(rows: arr)
//|> yield(name: "metadata")
  
consumption = from(bucket: "pe")
  |> range(start: 2023-03-01T00:00:00.00Z, stop: 2023-03-01T02:00:00.00Z)
  |> filter(fn: (r) => r["_measurement"] == "electricity")
  |> yield(name: "consumption")


jj = join.tables(
    method: "inner",
    left: consumption |> group(),
    right: metadata ,
    on: (l, r) => l.meter_id == r.meter_id,
    as: (l, r) => ({l with bill_meter_id: r.bill_meter_id}),
)
|> yield(name:"joined")

Werid. I think I’ve fixed it. I just added a keep() function and that works now in that it returns the joined table and I dont have to specify the yield() function on the consumption table.

import "array"
import "join"

arr = [
    {tenant_id: "1", tenant_name: "OrgA", meter_id: "CCC_L01_M9_R514", bill_meter_id: "22"},
    {tenant_id: "1", tenant_name: "OrgA", meter_id: "CCC_L01_M1_R45099", bill_meter_id: "22"},
    {tenant_id: "2", tenant_name: "OrgB", meter_id: "CCC_L01_M14_R45099", bill_meter_id: "22"}
]

metadata = array.from(rows: arr)
//|> yield(name: "metadata")
  
consumption = from(bucket: "pe")
  |> range(start: 2023-03-01T00:00:00.00Z, stop: 2023-03-01T02:00:00.00Z)
  |> filter(fn: (r) => r["_measurement"] == "electricity")
  |> filter(fn: (r) => r["_field"] == "value")
  |> keep(columns:["_value", "_time", "meter_id"])
 // |> yield(name: "consumption")


jj = join.tables(
    method: "inner",
    left: consumption |> group(),
    right: metadata ,
    on: (l, r) => l.meter_id == r.meter_id,
    as: (l, r) => ({l with bill_meter_id: r.bill_meter_id}),
)
|> yield(name:"joined")

Can anyone explain why this behaviour is happening?

Thanks

1 Like

Hello @MPH1984,
yes I don’t think you should have to yield twice. I’m not sure why the keep is affecting anything. It shouldn’t. I don’t know why that is happening. But sometimes things graph better on the InfluxDB UI than grafana.