Skip to content

Instantly share code, notes, and snippets.

@anmol2709
Created December 27, 2018 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anmol2709/be712847518264e6363f24cdc9f0b695 to your computer and use it in GitHub Desktop.
Save anmol2709/be712847518264e6363f24cdc9f0b695 to your computer and use it in GitHub Desktop.
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