Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
val counts: DataStream[(String, Int)] = text
// split up the lines in pairs (2-tuples) containing: (word,1)
.flatMap(_.toLowerCase.split("\\W+"))
.filter(_.nonEmpty)
.map((_, 1))
// group by the tuple field "0" and sum up tuple field "1"
.keyBy(0)
.sum(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment