有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何区分apache beam中KV实例中的两个键?

apachebeam的版本是2.15.0

在这个code中,类机场被用作KV实例的键,最后,为每个机场实例计算平均

c.output(KV.of(stats.airport, stats.timestamp));

但是,如果两个实例相同或不相同,apachebeam如何在内部比较两个键并返回?如果所有类成员具有相同的值,两个实例是否被视为相同的Document没有提到两个键的比较

如果有人能帮助我理解,我将不胜感激


共 (1) 个答案

  1. # 1 楼答案

    这实际上是在GroupByKey转换docs中解释的,这是在引擎盖下为Mean聚合执行的操作:

    Two keys of type K are compared for equality not by regular Java Object.equals(java.lang.Object), but instead by first encoding each of the keys using the Coder of the keys of the input PCollection, and then comparing the encoded bytes. This admits efficient parallel evaluation. Note that this requires that the Coder of the keys be deterministic (see Coder.verifyDeterministic()). If the key Coder is not deterministic, an exception is thrown at pipeline construction time.

    注意^{}使用^{},这是GroupByKey+Combine.GroupedValues的“速记”