Slide 11
Slide 11 text
mrjob Word Count Example
from mrjob.job import MRJob
import re
WORD_RE = re.compile(r"[\w']+")
class MRWordFreqCount(MRJob):
def mapper(self, _, line):
for word in WORD_RE.findall(line):
yield (word.lower(), 1)
def combiner(self, word, counts):
yield (word, sum(counts))
def reducer(self, word, counts):
yield (word, sum(counts))
if __name__ == '__main__':
MRWordFreqCount.run()
Define map() and reduce() functions
in standard Python
Python generators pass data back to
Hadoop
mrjob handles set-up and
configuration of job
$ python mrjob_wc.py readme.txt >
counts # local
$ python mrjob_wc.py readme.txt -r
emr > counts # EMR
$ python mrjob_wc.py readme.txt -r
hadoop > counts # Hadoop