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 "Robert.Zhang" <17...@qq.com> on 2020/07/08 07:41:01 UTC

flink state使用

Hello,all
目前遇到一个关于state的使用问题
&nbsp; &nbsp; &nbsp; DataStream<Tuple2<String, String&gt;&gt; result = iteration.closeWith(
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iteration.keyBy(0).process(new RichMapFunc());



我在richmapfunc里使用了state,那么每一次迭代的时候,这个state还是同一个吗?
如果我对result这个结果stream继续使用了keyby(0)的话,state也是同一个么?
此外,如果我对一个stream进行keyby之后,key一直是不变的,
但是map等operator之后返回的并非是keyedstream(operator不对key进行操作),是否只能继续keyby,还是有更好的方式

Re: flink state使用

Posted by Congxian Qiu <qc...@gmail.com>.
State 可以简单理解为一个 HashMap,Key 是 curretnly key(也就是 keyby 的 key)),value 是 state
存的值(可以是 value,list,map 等)

所有 state 的读写都有一个 currently,只能读到 currently key 对应的值。

在同一个 operator 中,同一个 key 能访问到之前存储过的 state 值,但是不能读取到其他 key 对应的值

Best,
Congxian


Robert.Zhang <17...@qq.com> 于2020年7月8日周三 下午3:58写道:

>
> 那就是在说,在iterativestream中,这个state可以正确的在每一次的迭代operator中传递并读取,那么结束迭代之后,假设得到的结果stream再进行keyby操作,因为operator不是同一个,此时就无法读取到前述迭代过程中的state,即便是同一个key
> 这样的理解对吗?
>
>
> Best Regards
>
>
>
>
>
> ------------------&nbsp;原始邮件&nbsp;------------------
> 发件人: "Congxian Qiu"<qcx978132955@gmail.com&gt;;
> 发送时间: 2020年7月8日(星期三) 下午3:48
> 收件人: "user-zh"<user-zh@flink.apache.org&gt;;
> 主题: Re: flink state使用
>
>
>
> Hi
>
> KeyedState 的操作实际会针对当前的 key,也就是 keyBy 之后得到的 key,但是这个 key 用户看不到。在一个 operator
> 中 state 的数目是你创建的数目,但是每个 state 可以有多个 KV 对,其中 K 是 keyby 的 key,V 可以是
> value,list,map 等。同一个 operator 上不同的 key 的 state 保证能够正确读写的。
>
> Best,
> Congxian
>
>
> Robert.Zhang <173603082@qq.com&gt; 于2020年7月8日周三 下午3:41写道:
>
> &gt; Hello,all
> &gt; 目前遇到一个关于state的使用问题
> &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; DataStream<Tuple2<String,
> String&amp;gt;&amp;gt; result =
> &gt; iteration.closeWith(
> &gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
> &amp;nbsp; &amp;nbsp;
> &gt; iteration.keyBy(0).process(new RichMapFunc());
> &gt;
> &gt;
> &gt;
> &gt; 我在richmapfunc里使用了state,那么每一次迭代的时候,这个state还是同一个吗?
> &gt; 如果我对result这个结果stream继续使用了keyby(0)的话,state也是同一个么?
> &gt; 此外,如果我对一个stream进行keyby之后,key一直是不变的,
> &gt;
> 但是map等operator之后返回的并非是keyedstream(operator不对key进行操作),是否只能继续keyby,还是有更好的方式

回复: flink state使用

Posted by "Robert.Zhang" <17...@qq.com>.
那就是在说,在iterativestream中,这个state可以正确的在每一次的迭代operator中传递并读取,那么结束迭代之后,假设得到的结果stream再进行keyby操作,因为operator不是同一个,此时就无法读取到前述迭代过程中的state,即便是同一个key
这样的理解对吗?


Best Regards





------------------&nbsp;原始邮件&nbsp;------------------
发件人: "Congxian Qiu"<qcx978132955@gmail.com&gt;; 
发送时间: 2020年7月8日(星期三) 下午3:48
收件人: "user-zh"<user-zh@flink.apache.org&gt;; 
主题: Re: flink state使用



Hi

KeyedState 的操作实际会针对当前的 key,也就是 keyBy 之后得到的 key,但是这个 key 用户看不到。在一个 operator
中 state 的数目是你创建的数目,但是每个 state 可以有多个 KV 对,其中 K 是 keyby 的 key,V 可以是
value,list,map 等。同一个 operator 上不同的 key 的 state 保证能够正确读写的。

Best,
Congxian


Robert.Zhang <173603082@qq.com&gt; 于2020年7月8日周三 下午3:41写道:

&gt; Hello,all
&gt; 目前遇到一个关于state的使用问题
&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; DataStream<Tuple2<String, String&amp;gt;&amp;gt; result =
&gt; iteration.closeWith(
&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&gt; iteration.keyBy(0).process(new RichMapFunc());
&gt;
&gt;
&gt;
&gt; 我在richmapfunc里使用了state,那么每一次迭代的时候,这个state还是同一个吗?
&gt; 如果我对result这个结果stream继续使用了keyby(0)的话,state也是同一个么?
&gt; 此外,如果我对一个stream进行keyby之后,key一直是不变的,
&gt; 但是map等operator之后返回的并非是keyedstream(operator不对key进行操作),是否只能继续keyby,还是有更好的方式

Re: flink state使用

Posted by Congxian Qiu <qc...@gmail.com>.
Hi

KeyedState 的操作实际会针对当前的 key,也就是 keyBy 之后得到的 key,但是这个 key 用户看不到。在一个 operator
中 state 的数目是你创建的数目,但是每个 state 可以有多个 KV 对,其中 K 是 keyby 的 key,V 可以是
value,list,map 等。同一个 operator 上不同的 key 的 state 保证能够正确读写的。

Best,
Congxian


Robert.Zhang <17...@qq.com> 于2020年7月8日周三 下午3:41写道:

> Hello,all
> 目前遇到一个关于state的使用问题
> &nbsp; &nbsp; &nbsp; DataStream<Tuple2<String, String&gt;&gt; result =
> iteration.closeWith(
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
> iteration.keyBy(0).process(new RichMapFunc());
>
>
>
> 我在richmapfunc里使用了state,那么每一次迭代的时候,这个state还是同一个吗?
> 如果我对result这个结果stream继续使用了keyby(0)的话,state也是同一个么?
> 此外,如果我对一个stream进行keyby之后,key一直是不变的,
> 但是map等operator之后返回的并非是keyedstream(operator不对key进行操作),是否只能继续keyby,还是有更好的方式