MapReduce Data Processing Model

Outline

Key-value pairs

  • Key-Value pairs: MapReduce basic data model
      Key                          Value
      City                         Sydney
      Employer                     Cloudera
  • Input, output, and intermediate records in MapReduce are represented as key-value pairs (aka name-value/attribute-value pairs)
  • A key is an identifier, for example, a name of attribute
    • In MapReduce, a key is not required to be unique.
  • A value is a data associated with a key
    • It may be simple value or a complex object
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

MapReduce Data Processing Model

Outline

MapReduce Model

  • MapReduce data processing model is a sequence of Map, Partition, Shuffle and Sort, and Reduce stages

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

MapReduce Model

  • An abstract MapReduce program: WordCount
      	  
      function Map(Long lineNo, String line):
        lineNo: the position no. of a line in the text
        line: a line of text
          for each word w in line:
            emit (w, 1)
      function Reduce(String w, List loc):
        w: a word
        loc: a list of counts outputted from map instances
          sum = 0
          for each c in loc:
            sum += c
          emit (word, sum)
                 

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

MapReduce Model

  • A diagram of data processing in MapReduce model

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

MapReduce Data Processing Model

Outline

Map phase

  • Map phase uses input format and record reader functions to derive records in the form of key-value pairs for the input data
  • Map phase applies a function or functions to each key-value pair over a portion of the dataset
    • In the case of a dataset hosted in HDFS, this portion is usually called as a block
    • If there are n blocks of data in the input dataset, there will be at least n Map tasks (also referred to as Mappers)
  • Each Map task operates against one filesystem (HDFS) block
  • In the diagram fragment, a Map task will call its map() function, represented by M in the diagram, once for each record, or key-value pair; for example, rec1, rec2, and so on.

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Map phase

  • Each call of the map() function accepts one key-value pair and emits zero or more key-value pairs
      
      map (in_key, in_value) -> list (intermediate_key, intermediate_value)
  • The emitted data from Mapper, also in the form of lists of key-value pairs, will be subsequently processed in the Reduce phase
  • Different Mappers do not communicate or share data with each other
  • Common Map() functions include filtering of specific keys, such as filtering log messages if you only wanted to count or analyse ERROR log messages
      	       
      Map (k, v) = if (ERROR in v) then emit (k, v)
  • Another example of Map() function would be to manipulate values, such as a function that converts a text value to lowercase
      	      
       Map (k, v) = emit (k, v.toLowercase ( ))
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Map phase

  • Partition function, or Partitioner, ensures each key and its list of values is passed to one and only one Reduce task or Reducer
  • The number of partitions is determined by the (default or user-defined) number of Reducers
  • Custom Partitioners are developed for various practical purposes
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

MapReduce Data Processing Model

Outline

Reduce Phase

  • Input of the Reduce phase is output of the Map phase (via shuffle-and sort)
  • Each Reduce task (or Reducer) executes a reduce() function for each intermediate key and its list of associated intermediate values
  • The output from each reduce() function is zero or more key-values
      		    
      reduce (intermediate_key, list (intermediate_value)) -> (out_key, out_value)
  • Note that, in the reality, an output from Reducer may be an input to another Map phase in a complex multistage computational workflow
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Example of Reduce Functions

  • The simplest and most common reduce() function is the Sum Reducer, which simply sums a list of values for each key
      reduce (k, list ) =
        {
          sum = 0
          for int i in list  :
            sum + = i
          emit (k, sum)
        }
  • A count operation is as simple as summing a set of numbers representing instances of the values you wish to count
  • Other examples of reduce() function are max() and average()
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

MapReduce Data Processing Model

Outline

Shuffle and Sort

  • Shuffle-and-sort is the process where data are transferred from Mapper to Reducer
    • It is the heart of MapReduce where the "magic" happens
  • The most important purpose of Shuffle-and-sort is to minimise data transmission through a network
  • In general, in Shuffle-and-Sort, the Mapper output is sent to the target Reduce task according to the partitioning function

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

MapReduce Data Processing Model

Outline

Combiner phase

  • A structure of Combiner phase

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Combiner phase

  • If the Reduce function is commutative and associative then it can be performed before the Shuffle-and-Sort phase
  • In this case, the Reduce function is called a Combiner function
  • For example, sum and count is commutative and associative, but average is not
  • The use of a Combiner can minimise the amount of data transferred to Reduce phase and in such a way reduce the network transmit overhead
  • A MapReduce application may contain zero Reduce tasks
  • In this case, it is a Map-Only application
  • Examples of Map-only MapReduce jobs
    • ETL routines without data summarization, aggregation and reduction
    • File format conversion jobs
    • Image processing jobs
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Combiner phase

  • Map-Only MapReduce

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Combiner phase

  • An election Analogy for MapReduce

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

MapReduce Data Processing Model

Outline

Example

  • For a database of 1 billion people, compute the average number of social contacts a person has according to age
  • In SQL like language
      
      SELECT age, AVG(contacts)
      FROM social.person
      GROUP BY age
  • If the records are stored in different datanodes then in Map function is the following
      function Map is
            input: integer K between 1 and 1000, representing a batch of 1
            million social.person records
            for each social.person record in the K-th batch do
              let Y be the person age
              let N be the number of contacts the person has
                produce one output record (Y,(N,1))
            repeat
      end function
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Example

  • Then Reduce function is the following
      function Reduce is
             input: age (in years) Y
             for each input record (Y,(N,C)) do
               Accumulate in S the sum of N
               Accumulate in C_new the sum of C
             repeat
             let A be S/C_new
             produce one output record (Y,(A,C_new ))
      end function
  • MapReduce sends the codes to the location of each data batch (not the other way around)
  • Question: the output from Map is multiple copies of (Y, (N, 1)), but the input to Reduce is (Y, (N, C)), so what fills the gap?
In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Example

  • A MapReduce application in Hadoop is a Java implementation of the MapReduce model for a specific problem, for example, word count

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Example

  • Sample processing on a screen

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Example

  • Sample processing on a screen

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

MapReduce Data Processing Model

Outline

Running MapReduce Jobs

  • Client submits Mapreduce job
  • YARN resource manager coordinates the allocation of computing resources in the cluster
  • YARN node manager(s): launch & monitor containers on machines in the cluster

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

Running MapReduce Jobs

  • MapReduce application master runs in a container, and coordinates the tasks in a MapReduce job
  • HDFS is used for sharing job files between the other files

      ORM

In HTML view press 'p' to see the lecture notes
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026

References

  • White T., Hadoop The Definitive Guide: Storage and Analysis at Internet Scale, O'Reilly, 2015
TOP              Created by Janusz R. Getta, ISIT312/ISIT912 Big Data Management, Spring, 2026