如何按键合并两个PCollection KV<>?
How to merge two PCollection KV<> by key?
我正在尝试为同一个键输出 SUM 和 COUNT。
例如。给定一个包含数百万个飞机延误事件的 .csv。
使用 Apache Beam (Java) 我想对每架飞机的延误持续时间求和,并计算每架飞机有多少延误。
每行有plane_id, delay_duration, date
,依此类推
我正在尝试创建两个 PCollections 并希望在输出之前将它们合并。
PCollection<KV<String, Integer>> sum = eventInfo.apply(MapElements.into(TypeDescriptors.kvs(TypeDescriptors.strings(),TypeDescriptors.integers())).via((Event.EventInfo gInfo) -> KV.of(gInfo.getKey('plane_id'), gInfo.getDuration()))).apply(Sum.integersPerKey());
PCollection<KV<String, Long>> count = eventInfo.apply(MapElements.into(TypeDescriptors.kvs(TypeDescriptors.strings(), TypeDescriptors.integers())).via((Event.EventInfo gInfo) -> KV.of(gInfo.getKey('plane_id'), gInfo.getDuration()))).apply(Count.perKey());
这两个 PCollections 按预期工作,但我不知道如何在 3 列中输出(合并它?) key |总和 |计数。
您将需要 CoGBK,这将帮助您共同定位您的总和并计算相同的密钥。
我正在尝试为同一个键输出 SUM 和 COUNT。 例如。给定一个包含数百万个飞机延误事件的 .csv。 使用 Apache Beam (Java) 我想对每架飞机的延误持续时间求和,并计算每架飞机有多少延误。
每行有plane_id, delay_duration, date
,依此类推
我正在尝试创建两个 PCollections 并希望在输出之前将它们合并。
PCollection<KV<String, Integer>> sum = eventInfo.apply(MapElements.into(TypeDescriptors.kvs(TypeDescriptors.strings(),TypeDescriptors.integers())).via((Event.EventInfo gInfo) -> KV.of(gInfo.getKey('plane_id'), gInfo.getDuration()))).apply(Sum.integersPerKey());
PCollection<KV<String, Long>> count = eventInfo.apply(MapElements.into(TypeDescriptors.kvs(TypeDescriptors.strings(), TypeDescriptors.integers())).via((Event.EventInfo gInfo) -> KV.of(gInfo.getKey('plane_id'), gInfo.getDuration()))).apply(Count.perKey());
这两个 PCollections 按预期工作,但我不知道如何在 3 列中输出(合并它?) key |总和 |计数。
您将需要 CoGBK,这将帮助您共同定位您的总和并计算相同的密钥。