Flink,如果多个记录满足条件,minBy 或 maxBy 的行为是什么

Flink, what's the behavior of minBy or maxBy if multiple records meet the condition

我是 Flink 的新手,我想知道如果有多个记录具有最小值,minBy 的行为是什么(猜测 maxBy 是相同的)。我注意到 Flink 在这种情况下只会输出一条记录,但是哪一条呢?第一个、最后一个还是随机的?

感谢您的帮助。

请注意,从 FLIP-134 起,DataStreams 上的所有这些关系方法,即 Windowed/KeyedStream#sum,min,max,minBy,maxBy,都计划被弃用。整个数据集 API 也计划最终被弃用。

像这样的关系方法的唯一长期支持是由 Table 和 SQL API 提供的。

但要回答您的问题,minBy 和 maxBy 的工作方式相同。

DataSet#maxBy 的 javadoc 说

If multiple values with maximum value at the specified fields exist, a random one will be picked.

AllWindowedStream#maxBy(int positionToMaxBy)KeyedStream#maxBy(int positionToMaxBy) 的 javadocs 说

If more elements have the same maximum value the operator returns the first by default.

以及 AllWindowedStream#maxBy(int positionToMaxBy, boolean first)AllWindowedStream#maxBy(int positionToMaxBy, boolean first) 的 javadocs 解释说

If [first is] true, then the operator return the first element with the maximum value, otherwise returns the last