Before the reduce function comes into the picture, the MapReduce framework groups all the map output as per the key and lines up the input for the reducer. It is again formed as a key-value pair wherein the key is the same as the output of the map function, but the value is now the list of values of all those map outputs having the same key. All the preceding map outputs now get grouped as follows:
<Country1, [1,1,1,1]> <Country2, [1,1]> <Country3, [1,1,1]>
Each of these above aggregated key-value pairs will be fed to the reduce function. A reduce function expects a key and a list of values as input. Now, we have a super simple task of addition in the reduce function. This function just needs to add up the number of elements in the list of values it receives and emit the output key-value pair in the form of <Country, Number-of-occurrences>
. Even reduce functions are stateless as they are isolated from the execution of other reduce functions. So,...