---
title: "MapReduce Driver Class:"  
description: "Although the mapper and reducer implementations are all we need to perform the MapReduce job, there is one more piece of code necessary in MapReduce:"  
author: "Anonymous User"  
published: 2016-05-06  
updated: 2018-03-14  
canonical: https://www.mindstick.com/blog/11069/mapreduce-driver-class  
category: "big data"  
tags: ["bigdata", "hadoop", "software development"]  
reading_time: 3 minutes  

---

# MapReduce Driver Class:

Although the mapper and reducer implementations are all we need to perform the [MapReduce](https://www.mindstick.com/Articles/12040/mapreduce-mapper-class) job, there is one more piece of code necessary in MapReduce: the driver which communicates with the Hadoop framework and specifies the configuration elements required to run a MapReduce job. This involves aspects such as telling Hadoop which Mapper and Reducer classes to use, where to find the [input data](https://www.mindstick.com/forum/161330/what-are-some-efficient-ways-to-handle-large-input-data-in-python) and in what format, and where to place the output data and how to format it. There is an additional variety of other [configuration options](https://answers.mindstick.com/qa/51647/what-are-the-custom-configuration-options-for-the-touch-bar-macbook-pro-models) that can be set here.

There is no default parent Driver class as a subclass; the driver logic usually exists in the main method of the class written to encapsulate a MapReduce job. Take a look at the following code snippet as an example driver. Don't worry about how each line works, though we should be able to work out generally what each is doing:

```
public class ExampleDriver{   ...   public static void main(String[] args) throws Exception   {          // Create a Configuration object that is used to set other options          Configuration conf = new Configuration() ;
        // Create the object representing the job        Job job = new Job(conf, "ExampleJob") ;
        // Set the name of the main class in the job jar file        job.setJarByClass(ExampleDriver.class) ;
       // Set the mapper class       job.setMapperClass(ExampleMapper.class) ;
       // Set the reducer class       job.setReducerClass(ExampleReducer.class) ;
       // Set the types for the final output key and value        job.setOutputKeyClass(Text.class) ;        job.setOutputValueClass(IntWritable.class) ;
      // Set input and output file paths          FileInputFormat.addInputPath(job, new Path(args[0])) ;          FileOutputFormat.setOutputPath(job, new Path(args[1]))
         // Execute the job and wait for it to complete          System.exit(job.waitForCompletion(true) ? 0 : 1);
       }}
```

\

It is not surprising that much of the setup involves [operations](https://www.mindstick.com/blog/304985/how-does-devops-bridge-the-gap-between-development-and-operations-teams-like-git) on a Job object. This includes setting the job name and specifying which classes are to be used for the mapper and reducer implementations.

Certain input/output configurations are set and, finally, the arguments passed to the main method are used to specify the [input and output](https://www.mindstick.com/forum/161309/what-are-the-features-of-the-console-class-for-input-and-output-in-java) locations for the job. This is a very common model that we will see often.

There are a number of [default values](https://www.mindstick.com/blog/10881/default-values) for configuration options, and we are implicitly using some of them in this class. Most notably, we don't say anything about the [file format](https://www.mindstick.com/forum/382/how-to-import-and-export-data-in-sql-server-from-different-file-format) of the input files or how the [output files](https://answers.mindstick.com/qa/34222/how-to-review-salesforce-data-loader-output-files) are to be written. These are defined through the InputFormat and OutputFormat classes. The default **input and output formats** are text files. There are multiple ways of expressing the format within text files in addition to particularly optimized binary formats.

A common model for less complex MapReduce jobs is to have the **Mapper and Reducer classes** as [inner classes](https://www.mindstick.com/forum/159219/how-can-i-test-a-class-that-has-private-methods-fields-or-inner-classes) within the driver. This allows everything to be kept in a [single file](https://www.mindstick.com/forum/161633/how-do-you-merge-multiple-text-files-into-a-single-file), which simplifies the code distribution.

---

Original Source: https://www.mindstick.com/blog/11069/mapreduce-driver-class

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
