.reduce() | .aggregate() | .apply() | .process() |
---|---|---|---|
ReduceFunction<T> ① 输入,计算,输出 数据类型都相同 | AggregateFunction<IN, ACC, OUT> ① 输入,计算,输出 数据类型可以不一样 ② 重写4个函数:createAccumulator(), add(), getResult(), merge() | WindowFunction<IN,OUT,KEY,W> ① IN 可迭代类型Iterable, OUT 收集器Collector, KEY 上游分组的字段 ② 重写apply(key, w, in, out)方法 | ProcessWindowFunction<IN,OUT,KEY,W> ① IN 可迭代类型Iterable, OUT 收集器Collector, KEY 上游分组的字段 ② 重写process(key, context, in, out)方法 ③ context中有: (1) watermark, (2) window.getStart、window.getEnd, (3) windowState, globalState, 都包含五种类型:State(ValueState)、MapState、ListState、ReducingState、AggregatingState (4) output() 侧输出流 |
ReduceFunction+WindowFunction ① 增量聚合函数处理窗口数据,每来一个数据就做一次聚合;等到窗口需要触发计算时,调用全窗口函数的处理逻辑输出结果 ② 这里的全窗口函数就不再缓存所有数据了,而是直接将增量聚合函数的结果拿来当作了全窗口函数中IN (Iterable类型) 的输入 ③ 表中列出的其他3个 增量函数+全窗口函数 也符合上述①②的规则 | AggregateFunction+WindowFunction | AllWindowFunction<IN,OUT,W> ① 因为没有分组,所以没有KEY,IN 可迭代类型Iterable, OUT 收集器Collector | |
ReduceFunction+ProcessWindowFunction | AggregateFunction+ProcessWindowFunction |