Book Image

YARN Essentials

Book Image

YARN Essentials

Overview of this book

Table of Contents (17 chapters)
YARN Essentials
About the Authors
About the Reviewers
Free Chapter
Need for YARN
YARN – Alternative Solutions

Practical examples of MRv1 and MRv2

We will now present a MapReduce example using both the old and new MapReduce APIs.

We will now write a MapReduce program in Java that finds all the anagrams (a word, phrase, or name formed by rearranging the letters of another, such as cinema, formed from iceman) presents them in an input file, and finally prints all the anagrams in the output file.

Here is the class that uses the old MapReduce API:

import java.util.Arrays;

import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;

import java.util.StringTokenizer;

 * The Anagram mapper class gets a word as a line from the HDFS input and sorts the
 * letters in the word and writes its back to the output collector as 
 * Key : sorted word (letters in the word sorted)
 * Value: the word itself as...