Apache flink Flink滑动计数窗口行为

Apache flink Flink滑动计数窗口行为,apache-flink,flink-streaming,Apache Flink,Flink Streaming,假设我们有这样的数据结构: Tuple2<ArryaList<Long>, Integer> 更新:根据@DavidAnderson的建议,我还尝试在reduceFunction中创建一个新元组,而不是修改t0,但结果相同 public Tuple2<ArrayList<Long>, Integer> reduce(Tuple2<ArrayList<Long>, Integer> t0, Tuple2<ArrayLi

假设我们有这样的数据结构:

Tuple2<ArryaList<Long>, Integer>
更新:根据@DavidAnderson的建议,我还尝试在
reduceFunction
中创建一个新元组,而不是修改
t0
,但结果相同

public Tuple2<ArrayList<Long>, Integer> reduce(Tuple2<ArrayList<Long>, Integer> t0, Tuple2<ArrayList<Long>, Integer> t1) throws Exception {
                         ArrayList<Long> times = t0.f0;

                         times.addAll(t1.f0);

                         return new Tuple2<>(times, t0.f1) ;
                     }
public Tuple2 reduce(Tuple2 t0,Tuple2 t1)引发异常{
ArrayList时间=t0.f0;
乘以所有(t1.f0);
返回新的Tuple2(次,t0.f1);
}
感谢David Anderson的建议,通过修改
reduce函数来解决以下问题。我们应该在
ReduceFunction
中创建一个新对象:

public Tuple2<ArrayList<Long>, Integer> reduce(Tuple2<ArrayList<Long>, Integer> t0, Tuple2<ArrayList<Long>, Integer> t1) throws Exception {
                         ArrayList<Long> times = new ArrayList<>();

                         times.addAll(t0.f0);
                         times.addAll(t1.f0);


                         return new Tuple2<>(times, t0.f1) ;
                     }
public Tuple2 reduce(Tuple2 t0,Tuple2 t1)引发异常{
ArrayList时间=新建ArrayList();
加总次数(t0.f0);
乘以所有(t1.f0);
返回新的Tuple2(次,t0.f1);
}
请注意,问题中的两种reduce方法都会导致错误的输出。 现在输出如下所示:

  • 前40个通道-->长度为100
  • 第二个40通道-->长度为200
  • 第三个40通道-->长度为300
  • 每40个通道-->长度为400,将保留
因此,Flink滑动计数窗口的行为是调用
ReduceFunction
每个滑动计数输入消息。因此,在我们有160000条输入消息的情况下,结果编号应为:
160000/100=1600

这是countWindow的实现

public WindowedStream<T, KEY, GlobalWindow> countWindow(long size, long slide) {
    return window(GlobalWindows.create())
            .evictor(CountEvictor.of(size))
            .trigger(CountTrigger.of(slide));
}
公共窗口流计数窗口(长尺寸、长幻灯片){
返回窗口(GlobalWindows.create())
.驱逐器(数量驱逐器(尺寸))
.trigger(CountTrigger.of(slide));
}

它的行为和你期望的不一样。窗口每100个元素(幻灯片)触发一次,无论它是否包含400个元素(大小)。大小控制最多保留多少元素。

您是否尝试过让reduce函数创建一个新元组,而不是修改t0?@DavidAnderson我根据您的建议更新了问题。结果是相同的。@DavidAnderson您能详细说明一下Flink中滑动计数窗口的行为吗?例如,对于
countWindow(400100)
,根据
滑动窗口的定义,我希望它调用
ReduceFunction
,对最后400条消息,每100条输入消息调用一次。我说得对吗?
public WindowedStream<T, KEY, GlobalWindow> countWindow(long size, long slide) {
    return window(GlobalWindows.create())
            .evictor(CountEvictor.of(size))
            .trigger(CountTrigger.of(slide));
}