Flink keyed stream key is null

后端 未结 1 485
挽巷
挽巷 2021-01-22 19:41

I am trying to perform a map operation on a KeyedStream in Flink:

stream.map(new JsonToMessageObjectMapper())
                    .keyBy(\"keyfield\")
                   


        
相关标签:
1条回答
  • 2021-01-22 20:10

    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.

    0 讨论(0)
提交回复
热议问题