Skip to content

Instantly share code, notes, and snippets.

@hmaurer
Created May 28, 2013 01:12
Show Gist options
  • Save hmaurer/5659927 to your computer and use it in GitHub Desktop.
Save hmaurer/5659927 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'learn_mapreduce'
mr = MapReduce.new
mr.map do |record|
emit(record[0], 1)
end
mr.reduce do |key, list_of_values|
count = list_of_values.inject { |sum,i| sum + i }
emit([key, count])
end
data = [
["Jim", "Sue"],
["Sue", "Jim"],
["Lin", "Joe"],
["Joe", "Lin"],
["Jim", "Kai"],
["Kai", "Jim"],
["Jim", "Lin"],
["Lin", "Jim"]
]
(emitted, shuffled, output) = mr.run(data)
output.each do |value|
puts value.inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment