[ 
https://issues.apache.org/jira/browse/FLINK-30048?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17635807#comment-17635807
 ] 

Yanfei Lei commented on FLINK-30048:
------------------------------------

Sorry for the late reply. As [~masteryhx] mentioned, since the data structures 
of state backends are different from [Java 
Map|https://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/util/HashMap.java#l796],
 'Remove' is not in-place, returning the original value on 'remove' requires 
additional cost, I'm also +1 for leaving the interface as it is.

 

> MapState.remove(UK key) is better to return the old value.
> ----------------------------------------------------------
>
>                 Key: FLINK-30048
>                 URL: https://issues.apache.org/jira/browse/FLINK-30048
>             Project: Flink
>          Issue Type: Improvement
>          Components: API / DataStream, Runtime / State Backends
>            Reporter: xljtswf
>            Priority: Major
>
> Hi all:
> I found the MapState.remove(UK key) just returns nothing, and the Java Map 
> Interface returns the old value associated with the key.
> Consider the flollowing example from the Learn Flink Event-driven Application
> [链接标题|https://nightlies.apache.org/flink/flink-docs-release-1.16/docs/learn-flink/event_driven/#the-ontimer-method]
>  ,
> we want to get the value with the timestamp and then delete the timestamp, 
> with current inplement, we must first call mapState.get(key),then call 
> mapState.remove(key). it will search the key 2 times, I think it is not 
> necessary. If mapState.remove(key) can return the old value, then we can just 
> call mapState.remove(key) and get the old value and save the unnecessary 2nd 
> search in the map.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to