分享

Flink时间窗口触发计算的问题

flink触发当前窗口计算的前提是下一条数据在当前窗口的结束时间之后,我现在想要实现一个功能是每进来一条数据都去统计当前窗口的数据,我自定义的触发器好像不起作用,请问这个怎么处理呀?我新手,刚刚学习,不太懂,求教
public TriggerResult onElement(Object element, long timestamp, TimeWindow window, TriggerContext ctx) throws Exception {
    if (window.maxTimestamp() <= ctx.getCurrentWatermark()) {
        return TriggerResult.FIRE;
    } else {
        ctx.registerEventTimeTimer(window.maxTimestamp());
        return TriggerResult.FIRE;
    }
}

public TriggerResult onEventTime(long time, TimeWindow window, TriggerContext ctx) {
    return TriggerResult.CONTINUE;
}

public TriggerResult onProcessingTime(long time, TimeWindow window, TriggerContext ctx) throws Exception {
    return TriggerResult.CONTINUE;
}

public void clear(TimeWindow window, TriggerContext ctx) throws Exception {
    ctx.deleteEventTimeTimer(window.maxTimestamp());
}

public void onMerge(TimeWindow window, OnMergeContext ctx) {
    long windowMaxTimestamp = window.maxTimestamp();
    if (windowMaxTimestamp > ctx.getCurrentWatermark()) {
        ctx.registerEventTimeTimer(windowMaxTimestamp);
    }

}

已有(4)人评论

跳转到指定楼层
秋至丶枫已落 发表于 2019-5-5 16:19:47
困扰挺久了,感觉应该是我触发器写的有问题,这个应该怎么做呀,我现在要实现一个滑动窗口,每进来一条数据都去统计过去一小时的数据
回复

使用道具 举报

秋至丶枫已落 发表于 2019-5-5 19:59:08
好像这个代码可以触发...造的数据有问题,数据被丢弃了没有纳入统计
回复

使用道具 举报

admin 发表于 2020-12-17 18:32:25
Flink窗口什么时候触发计算及计算方式
https://www.aboutyun.com/forum.php?mod=viewthread&tid=29986
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条