Created
December 13, 2015 21:52
-
-
Save zezutom/edbdc5b1dd75e4b990a5 to your computer and use it in GitHub Desktop.
Spark's RDD transformations to arrive at a word count solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rdd | |
| .flatMap(_.split("\\s")) // Split on any white character | |
| .map(_.replaceAll( | |
| "[,.!?:;]", "") // Remove punctuation and transfer to lowercase | |
| .trim | |
| .toLowerCase) | |
| .filter(!_.isEmpty) // Filter out any non-words | |
| .map(word => (word, 1)) // Finally, count words | |
| .reduceByKey(_ + _) | |
| .sortByKey() // and sort the word counts in a lexical order |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment