在使用flink中的状态管理器时,由于需求背景我选用了MapState存储结构,但是在使用过程中发现修改存储对象的时候并没有MapState中的值并没有自动更新,这让我产生了很大的疑惑,看官方文档和flink源码中我都一直把MapState认为是类似于Map结构的,那自然认为修改里面的存储对象时整个map会自动更新,但是实际使用和测试下来确发现不是这样。
先贴一段官方文档:
MapState<UK, UV>: This keeps a list of mappings. You can put key-value pairs into the state and retrieve an Iterable over all currently stored mappings. Mappings are added using put(UK, UV) or putAll(Map<UK, UV>). The value associated with a user key can be retrieved using get(UK). The iterable views for mappings, keys and values can be retrieved using entries(), keys() and values() respectively. You can also use isEmpty() to check whether this map contains any key-value mappings.
接下来再贴一下代码:
首先来看map中修改对象的case:
// 实体类
public class OutputEntity {
private Integer amt;
public static OutputEntity getOneOutput(Integer amt){
OutputEntity output = new OutputEntity(amt);
output.amt = 10;
return output;
}
public OutputEntity(Integer amt){
this.amt = amt;
}
public void incr(Integer newAmt){
this.amt += newAmt;
}
public Integer getAmt() {
return amt;
}
public void