Flink : Purging Process Window 函数数据

Flink :Purging Process Window function Data

我需要在 flink 中进行聚合 window。 我不能使用聚合函数。因为 getResult 计算需要我访问状态。 所以我尝试将聚合与流程一起使用:

   .aggregate( 
    new AggregateFunction<Entry, Double, Double>() {
                       ...........
                    };
            , new ProcessWindowFunction<Double,Result,Entry,TimeWindow>() {

                @Override
                public void process(Entry item,
                        ProcessWindowFunction<Double, Result, Entry, TimeWindow>.Context ctx,
                        Iterable<Double> aggInput, Collector<Result> output) throws Exception {


                }

    }

但是,我仍然只需要 aggInput 的最新值,而且我没有看到将这些值保存在内存中的理由,在我的应用程序中它可能是数百万的数据。所以我想我是否可以每次清除 window 数据。

当你把一个AggregateFunction和一个ProcessWindowFunction组合在一起时,只有聚合的最新值保持在window状态,发送到process方法的Iterable只会包含一个预先聚合的条目。 (ReduceFunction 的工作方式相同。)

也就是说,你要找的优化已经有了。 documentation 有更多细节。