Skip to content

Instantly share code, notes, and snippets.

@douglaz
Last active August 29, 2015 14:28
Show Gist options
  • Save douglaz/e612f5964bcbafdb29cf to your computer and use it in GitHub Desktop.
Save douglaz/e612f5964bcbafdb29cf to your computer and use it in GitHub Desktop.
Designing Data-Intensive Applications Book: MongoDB Map-Reduce example rewritten in Spark
val monthySharkReport = observations
.filter(_.family == "Sharks")
.map { o =>
val year = o.observationTimestamp.getYear
val month = o.observationTimestamp.getMonthOfYear
(year, month) -> o.numAnimals
}
.reduceByKey(_ + _)
.collect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment