Skip to content

Instantly share code, notes, and snippets.

@josephpconley
Created October 9, 2015 15:06
Show Gist options
  • Save josephpconley/c330f59bb0ca42dcf368 to your computer and use it in GitHub Desktop.
Save josephpconley/c330f59bb0ca42dcf368 to your computer and use it in GitHub Desktop.
Spark code for following word count text: Betty Botta bought some butter; "But," said she, "this butter's bitter! If I put it in my batter It will make my batter bitter. But a bit o' better butter Will but make my batter better." Then she bought a bit o' butter Better than the bitter butter, Made her bitter batter better. So 'twas better Betty B…
sc.textFile("hdfs://localhost/jconley/input/wc.txt").flatMap(_.trim.split("""[\s\W]+""")).map(w => w -> 1).reduceByKey(_ + _).sortBy(_._2, ascending = false).foreach(println)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment