Role of the mapper
The primary purpose of the mapper is to emit data that the reducer will later aggregate into a final. In this trivial example, each occurrence of a word results in a (word, 1) pair since we're giving a single appearance of a word a score of 1. We very well could have emitted the word by itself (that is, 'amet') and put the score of 1 in the reducer; however, this would have made the code less general. If we wanted to give a heavier weighting to certain words, we'd merely change our mapper to output a different number based on the word and would leave our reducer code as-is.
The following code block shows how we would give the word amet a score of 10 while all other words count as 1. Of course, this is no longer counting ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access