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 ...

Get Serverless Design Patterns and Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.