concept mapper in category hadoop

appears as: mappers, mappers, mapper, The mapper, The mappers, The mapper, mapper
Hadoop in Practice, Second Edition

This is an excerpt from Manning's book Hadoop in Practice, Second Edition.

The goal of this reducer is to create an output line for each word and a list of the document IDs in which the word appears. The MapReduce framework will take care of calling the reducer once per unique key outputted by the mappers, along with a list of document IDs. All you need to do in the reducer is combine all the document IDs together and output them once in the reducer, as you can see in the following code:

With DistCp 2 you can use an alternative strategy, where the mappers pick up work directly as opposed to having it preallocated. This is called the dynamic copy strategy, and it’s activated with the -strategy dynamic argument. The net effect of adding this argument is improved copy times, as the faster mappers can pick up the slack of the slower mappers.

Hadoop in Action

This is an excerpt from Manning's book Hadoop in Action.

MapReduce programs are executed in two main phases, called mapping and reducing. Each phase is defined by a data processing function, and these functions are called mapper and reducer, respectively. In the mapping phase, MapReduce takes the input data and feeds each data element to the mapper. In the reducing phase, the reducer processes all the outputs from the mapper and arrives at a final result.

Our strategy is to have mapper calculate the maximum over its individual split. Each mapper will output a single value at the end. We have a single reducer that looks at all those values and outputs the global maximum. Listing 4.6 depicts the Python script for a mapper to compute the maximum over a split.

Listing 4.6. AttributeMax.py: Python script to find maximum value of an attribute
#!/usr/bin/env python import sys index = int(sys.argv[1]) max = 0 for line in sys.stdin: fields = line.strip().split(",") if fields[index].isdigit(): val = int(fields[index]) if (val > max): max = val else: print max

The script is not complicated. It has a for loop to read one record at a time. It tokenizes the record into fields and updates the maximum if the user-specified field is bigger. Note that the mapper doesn’t output any value until the end, when it sends out the maximum value of the entire split. This is different from what we’ve seen before, where each record sends out one or more intermediate records to be processed by the reducers.

Given the parsimonious output of the mapper, we can use the default IdentityReducer to record the (sorted) output of the mappers.

bin/hadoop jar contrib/streaming/hadoop-0.19.1-streaming.jar
-input input/apat63_99.txt
-output output
-mapper 'AttributeMax.py 8'
-file playground/AttributeMax.py
-D mapred.reduce.tasks=1

The mapper is 'AttributeMax.py 8'. It outputs the maximum of the ninth column in a split. The single reducer collects all the mapper outputs. Given seven mappers, the final output of the above command is this:

Listing 5.1. Driver for chaining mappers within a MapReduce job