Hi everyone,
I have a problem performing an left outer join, where i get an error message which i don’t really understand based on the documentation on the new join package and the following blog i went through Outer Joins in Flux | InfluxData.
The query looks like following:
table1 = from(bucket: "metrics")
|> range(start: -21m)
|> filter(fn: (r) => r._measurement == "device" and r.measurement_type == "metrics" and (r._field == "bri" or r._field == "cmd_val" or r._field == "snaga"))
|> last()
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|> group(columns: ["device_address"])
|> sort(columns: ["_time"], desc: true)
|> limit(n: 1)
table2 = from(bucket: "metrics")
|> range(start: -21m)
|> filter(fn: (r) => r._measurement == "device" and r.measurement_type == "brightness" and r._field == "cmd_val")
|> last()
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|> group(columns: ["device_address"])
|> sort(columns: ["_time"], desc: true)
|> limit(n: 1)
combined = join.left(left: table1, right: table2, on: (l, r) => l.device_address == r.device_address, as: (l, r) => {
return {
device_address: l.device_address,
bri: if exists r.cmd_val then int(v: r.cmd_val) else l.bri,
snaga: l.snaga,
cmd_tag: if exists r.cmd_tag then r.cmd_tag else l.cmd_tag,
cmd_val: if exists l.cmd_val then l.cmd_val else r.cmd_val
}
})
|> group(columns: ["result"])
|> yield(name: "combined")
The error i get is:
runtime error @31:12-39:3: left: table is missing label cmd_val
The ,cmd_val, in the first table might not appear if no errors are present on any device. If all devices have errors then ,bri, and ,snaga, would not appear and only ,cmd_val, will be present. I could add map to the table1 and add any column with some default value if the column does not exist and then all 3 columns would always exist, but i don’t know if that is necessary, as i don’t understand the error.
I get also the similar message on different columns if the right table (table2) is totally empty. I saw an opened issue join.tables() method: "full" with an empty table returns "table is missing label _value" · Issue #5134 · influxdata/flux · GitHub which addresses something similar, so i assume that this case is a bug.