执行左外连接
使用 join.left()
对两个数据流执行左外连接。左连接为左数据流中的每一行输出一行,其中包含来自右数据流的匹配数据。如果右数据流中没有匹配的数据,则来自右数据流的非组键列的值为null。
使用 join.left 连接您的数据
导入
join
包。定义要连接的左和右数据流
- 每个流必须有一个或多个具有公共值的列。列标签不需要匹配,但列值需要匹配。
- 每个流应具有相同的 组键。
有关更多信息,请参阅连接数据要求。
使用
join.left()
将两个流连接在一起。提供以下参数
以下示例使用来自 machineProduction 示例数据集的过滤选择作为左数据流,并使用 array.from()
创建的临时表作为右数据流。
示例数据分组
以下示例取消分组左流以匹配右流的分组。两个流连接在一起后,连接后的数据按 stationID
分组。
import "array"
import "influxdata/influxdb/sample"
import "join"
left =
sample.data(set: "machineProduction")
|> filter(fn: (r) => r.stationID == "g1" or r.stationID == "g2" or r.stationID == "g3")
|> filter(fn: (r) => r._field == "oil_temp")
|> limit(n: 5)
right =
array.from(
rows: [
{station: "g1", opType: "auto", last_maintained: 2021-07-15T00:00:00Z},
{station: "g2", opType: "manned", last_maintained: 2021-07-02T00:00:00Z},
],
)
join.left(
left: left |> group(),
right: right,
on: (l, r) => l.stationID == r.station,
as: (l, r) => ({l with opType: r.opType, maintained: r.last_maintained}),
)
|> group(columns: ["stationID"])
此页是否对您有帮助?
感谢您的反馈!