concept map() in category data

This is an excerpt from Manning's book Hadoop in Action.
The main functional distinction between WordCount.java and our MapReduce pseudo-code is that in WordCount.java, map() processes one line of text at a time whereas our pseudo-code processes a document at a time. This distinction may not even be apparent from looking at WordCount.java as it’s Hadoop’s default configuration.
The argument byValue will need a little explanation. In the standard Mapper model, the output key/value pairs are serialized and written to disk,[1] prepared to be shuffled to a reducer that may be at a completely different node. Formally this is considered to be passed by value, as a copy of the key/value pair is sent over. In the current case where we can chain one Mapper to another, we can execute the two in the same JVM thread. Therefore, it’s possible for the key/value pairs to be passed by reference, where the output of the initial Mapper stays in place in memory and the following Mapper refers to it directly in the same memory location. When Map1 calls OutputCollector.collect (K k, V v), the objects k and v pass directly to Map2’s map() method. This improves performance by not having to clone a potentially large volume of data between the mappers. But doing this can violate one of the more subtle “contracts” in Hadoop’s MapReduce API. The call to OutputCollector.collect(K k, V v) is guaranteed to not alter the content of k and v. Map1 can call OutputCollector.collect(K k, V v) and then use the objects k and v afterward, fully expecting their values to stay the same. But if we pass those objects by reference to Map2, then Map2 may alter them and violate the API’s guarantee. If you’re sure that Map1’s map() method doesn’t use the content of k and v after calling OutputCollector.collect(K k, V v), or that Map2 doesn’t change the value of its k and v input, you can achieve some performance gains by setting byValue to false. If you’re not sure of the Mapper’s internal code, it’s best to play safe and let byValue be true, maintaining the pass-by-value model, and be certain that the Mappers will work as expected.
First we see that mappers receive data from two files, Customers and Orders. Each mapper knows the filename of the data stream it’s processing. The map() function is called with each record, and the main goal of map() is to package each record such that joining on the reduce side is possible.
Recall that in the MapReduce framework, map() outputs records as key/value pairs that are partitioned on the key, and all records of the same key will end up in a single reducer and be processed together. For joining, we would want the map() function to output a record package where the key is the group key for joining—the Customer ID in this case. The value in this key/value package will be the original record, tagged with the data source (i.e., filename). For example, for the record
3,A,12.95,02-Jun-2008from the Orders file, map() will output a key/value pair where the key is "3", the Customer ID that will be used to join with records from the Customers file. The value output by map() is the entire record wrapped by a tag "Orders".
After map() packages each record of the inputs, MapReduce’s standard partition, shuffle, and sort takes place. Note that as the group key is set to the join key, reduce() will process all records of the same join key together. The function reduce() will unwrap the package to get the original record and the data source of the record by its tag. We see that for group keys (Customer IDs) "1" and "2", the reduce() function gets two values. One value is tagged with "Customers" and the other value is tagged with "Orders". For the map output with (group) key "4", reduce() will only see one value, which is tagged with "Customers". This is expected as there is no record in Orders with a Customer ID of "4". On the other hand, reduce() will see three values for the (group) key "3". This is due to one record from Customers and two more from Orders.