Mazen Ezzeddine
Mazen Ezzeddine

Reputation: 822

coProcessFunction vs keyedCoProcessFunction on connected keyed streams

In referring to Flink code samples, I observed that when connecting two streams using the connect operator, both coProcessFunction and keyedCoProcessFunction are being extended almost interchangeably and identically when operating on keyed streams (overriding processElement1, processElement2, and onTimer), So when operating on keyed streams what is the difference between extending CoProcessFunction as compared to keyedCoProcessFunction to implementent the business logic of the keyed connected stream?

Thank you.

Upvotes: 1

Views: 1687

Answers (1)

David Anderson
David Anderson

Reputation: 43707

KeyedCoProcessFunction and KeyedProcessFunction were added somewhat recently. The difference compared to the non-keyed flavors is that the current key is available in the Context that gets passed to the various processElement and onTimer methods.

If you try to use keyed state or timers in a ProcessFunction or CoProcessFunction, it will work if you are actually in a keyed context, and will throw an exception if you are not.

Upvotes: 4

Related Questions