[ https://issues.apache.org/jira/browse/FLINK-32480?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17740022#comment-17740022 ]
Viktor Feklin commented on FLINK-32480: --------------------------------------- [~masteryhx] , please read description carefully - question is not about the way you create default instance (although i think supplier pattern would be more suitable instead of object cloning). Main question - why newly created instance not fixed as current state. Second call to value() - return new instance again. Simple example for your understanding (assertion will fail untill i manyaly fix state with update()): {code:java} assert contextState.value() == contextState.value(){code} > Keyed State always returns new value instance > --------------------------------------------- > > Key: FLINK-32480 > URL: https://issues.apache.org/jira/browse/FLINK-32480 > Project: Flink > Issue Type: Bug > Components: API / State Processor > Affects Versions: 1.14.6 > Reporter: Viktor Feklin > Priority: Major > > I create ValueState with default value. Then i access value in the map > function (multiple times with the same partition key). > Expected behavior: > * First call to value() should return new instance > * Second call to value should return instance created in first call (just > like Map#computeIfAbsent) > Actual dehavior: > * every call to value() return new instance until we manualy set it with > update() function. > According to source code - we can call update only once to assign value to > current key. But from the user poin of view - it happends to call update() > every time - because i do not know if value was already asigned or just > created. > ---------------------------- > Currently my code looks like: > {code:java} > List<Integer> context = contextState.value(); > contextState.update(context); {code} > May be there is some logic for immutable objects, but for mutable objects it > looks awkward > > > -- This message was sent by Atlassian Jira (v8.20.10#820010)