val topXNumbers = randomNumbers .filter(_ > 1000) //Stage 1 .map(value => (value, 1)) // Stage 1 .groupByKey() //Stage 2 .map(value => (value._1, value._2.sum)) //Stage 2 .sortBy(_._2, false) //Stage 3 .count() // Stage 3