Using MapReduce
Boston University
A framework for computation on large data sets that are fragmented and replicated across a cluster of machines.
The original version was Google’s MapReduce system.
















MRJob libraryid,name,dob,emaildob is in the form yyyy-mm-ddmap should:



reduce should:





_ to “throw away” the keymap method will output pairs in which
yield to return the value (like “return”)str class includes a method named split().
str list containing the componentswould output:
mapline represents one record.
111,Alan Turing,1912-06-23,al@aol.comline on the hyphens?reduce

counts is a list of “1”ssum() adds up a listyield rather than returnid,name,dob,emaildob is in the form yyyy-mm-ddmap should behave as before:
reduce needs to:
("06", 2) → (None, (2, 06))("12", 3) → (None, (3, 12))("03", 1) → (None, (1, 03))(None, [(2, 06), (3, 12), (1, 03)]) → (3, 12)class Lecture_Ex_2(MRJob):
def steps(self):
return [
MRStep(mapper = self.mapper_get_months,
reducer = self.reducer_count_months),
MRStep(mapper = self.mapper_single_key,
reducer = self.reducer_max)]
def mapper_get_months(self, _, line):
words = line.split(',')
year, month, day = words[2].split('-')
yield (month, 1)
def reducer_count_months(self, month, counts):
yield (month, sum(counts))
def mapper_single_key(self, month, counts):
yield (None, (counts, month))
def reducer_max(self, _, month_count_pairs):
yield max(month_count_pairs)
if __name__ == '__main__':
Lecture_Ex_2.run()