AggregateFunction 是什么
Flink 的AggregateFunction是一个基于中间计算结果状态进行增量计算的函数。由于是迭代计算方式,所以,在窗口处理过程中,不用缓存整个窗口的数据,所以效率执行比较高。
AggregateFunction定义
/**
* The {@code AggregateFunction} is a flexible aggregation function, characterized by the
* following features:
*
* <ul>
* <li>The aggregates may use different types for input values, intermediate aggregates,
* and result type, to support a wide range of aggregation types.</li>
*
* <li>Support for distributive aggregations: Different intermediate aggregates can be
* merged together, to allow for pre-aggregation/final-aggregation optimizations.</li>
* </ul>
*
* <p>The {@code AggregateFunction}'s intermediate aggregate (in-progress aggregation state)
* is called the <i>accumulator</i>. Values are added to the accumulator, and final aggregates are
* obtained by finalizing the accumulator state. This supports aggregation functions where the
* intermediate state needs to be different than the aggregated values and the final result type,
* such as for example <i>average</i> (which typically keeps a count and sum).
* Merging intermediate aggregates (partial aggregates) means merging the accumulators.
*
* <p>The AggregationFunction itself is s

Flink的AggregateFunction提供了一种基于中间状态的增量计算方式,适用于窗口处理,提高效率。它需要实现createAccumulator、add、merge和getResult四个接口。举例来说,一个计算平均值的demo中,AggregateFunction接收(String, Int)作为输入,(0, 0)作为初始值,累加分数并计数,最后合并分区结果并计算平均值。"
44339673,4238265,选择排序算法详解:时间复杂度与空间复杂度分析,"['排序算法', '选择排序']
最低0.47元/天 解锁文章
3379

被折叠的 条评论
为什么被折叠?



