I am trying to perform a map operation on a KeyedStream in Flink:
stream.map(new JsonToMessageObjectMapper())
.keyBy(\"keyfield\")
The problem is that you try to access the keyed state in the open()
method.
Keyed state maintains a state instance for each key. In your example you are using MapState
. So you have one MapState
instance for each key. When accessing the state, you'll always get the state instance that corresponds to the key of the currently processed record. In a MapFunction
(like in your example) this would be the record that is passed to the map()
method.
Since open()
is not called with a record, the current key in open()
is null
and it is not possible to access the keyed state.