apache beam 的版本是 2.15.0
。
在此code ,类 Airport 用作 KV 实例的 Key,最后,计算每个 Airport 实例的 mean 。
c.output(KV.of(stats.airport, stats.timestamp));
但是apache beam如何在内部比较两个键并返回两个实例是否相同?如果所有类成员具有相同的值,两个实例是否被视为相同? Document没有提到两个键的比较。
如果有人能帮助我理解,我将不胜感激。
最佳答案
这实际上在 GroupByKey
转换中进行了解释 docs ,这是在 Mean
聚合的幕后完成的操作:
Two keys of type
K
are compared for equality not by regular JavaObject.equals
(java.lang.Object
), but instead by first encoding each of the keys using theCoder
of the keys of the inputPCollection
, and then comparing the encoded bytes. This admits efficient parallel evaluation. Note that this requires that theCoder
of the keys be deterministic (seeCoder.verifyDeterministic()
). If the keyCoder
is not deterministic, an exception is thrown at pipeline construction time.
请注意 Mean
使用Combine.PerKey
这是 GroupByKey
+ Combine.GroupedValues
的“简写”。
关于java - java如何区分apache beam中KV实例中的两个键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57831948/