Alternative to deprecated method DataStream.keyBy()

Viewed 989

On Flink 1.11 DataStream API page, there is a WindowWordCount program which uses keyBy(), however, this method is deprecated, I couldn't find any examples as to how to rewrite it without using keyBy(). Any suggestions will be much appreciated.

I use Intellij; it warns keyBy() is deprecated. This is the only link I could find.

1 Answers

The forms of keyBy that take an Integer or String parameter have been deprecated. You should use the form of keyBy that takes a KeySelector function -- e.g., replace

stream.keyBy("id")

with

stream.keyBy(event -> event.id)

and replace

streamOfTuples.keyBy(0)

with

streamOfTuples(tuple -> tuple.f0)
Related