Book Image

YARN Essentials

Book Image

YARN Essentials

Overview of this book

Table of Contents (17 chapters)
YARN Essentials
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Need for YARN
9
YARN – Alternative Solutions
Index

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 AnagramMapperOldAPI.java class that uses the old MapReduce API:

import java.io.IOException;
import java.util.Arrays;

import org.apache.hadoop.io.Text;
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...