You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-zh@flink.apache.org by kcz <57...@qq.com> on 2020/07/06 06:15:14 UTC

回复: 如何在窗口关闭的时候清除状态

用了window一天的窗口,这个开窗flink会自己将一天的数据自动清除的吧




------------------&nbsp;原始邮件&nbsp;------------------
发件人:&nbsp;"Congxian Qiu"<qcx978132955@gmail.com&gt;;
发送时间:&nbsp;2020年7月5日(星期天) 中午11:56
收件人:&nbsp;"user-zh"<user-zh@flink.apache.org&gt;;

主题:&nbsp;Re: 如何在窗口关闭的时候清除状态



看上去这个需求是 一天的窗口,每个小时都 trigger 一次,希望 state 在 1 天之后进行清理。
你可以尝试一下 TTL[1] State
另外想问一下,你自己写 ProcessWindowFunction 的话,为什么不考虑 KeyedProcessFunction[2] 呢

[1]
https://ci.apache.org/projects/flink/flink-docs-release-1.10/zh/dev/stream/state/state.html#%E7%8A%B6%E6%80%81%E6%9C%89%E6%95%88%E6%9C%9F-ttl
[2]
https://ci.apache.org/projects/flink/flink-docs-release-1.10/zh/dev/stream/operators/process_function.html#the-keyedprocessfunction
Best,
Congxian


JasonLee <17610775726@163.com&gt; 于2020年7月4日周六 下午8:29写道:

&gt; 设置一下状态过期的时间呢
&gt;
&gt;
&gt; | |
&gt; JasonLee
&gt; |
&gt; |
&gt; 邮箱:17610775726@163.com
&gt; |
&gt;
&gt; Signature is customized by Netease Mail Master
&gt;
&gt; 在2020年07月03日 14:02,18579099920@163.com 写道:
&gt;
&gt; 大家好,我有一个需求,我在ProcessWindowFunction算子中定义了一个valueState,我希望在窗口关闭的时候能够将状态清理。我应该在哪里清理呢?
&gt;
&gt; 1.刚开始我选择在ProcessWindowFunction算子的process方法中清理,但是这里会有一个问题,我事件时间窗口开1天,我写了一个trigger,每隔一个小时输出一次结果。
&gt;
&gt; 如果我在process方法中清理,每隔一个小时就会被清理,而valueState中存的是我的中间结果,应该在窗口关闭的时候被清理(即一天之后)。这应该怎么办呢?
&gt;
&gt;
&gt;
&gt; 18579099920@163.com
&gt;