The following code is a typical example of a MapReduce program for Hadoop. Its purpose is to take a number of input files and return a count of each word located in them.
We will be running this application in order to illustrate how the files we added to the FS can be processed.
Add the preceding code into a new file called WordCount.java
created in vim /home/pi/hadoop/apps/WordCount.java
:
package org.myorg; import java.io.IOException; import java.util.*; import org.apache.hadoop.fs.Path; import org.apache.hadoop.conf.*; import org.apache.hadoop.io.*; import org.apache.hadoop.mapred.*; import org.apache.hadoop.util.*;
The preceding code includes the various libraries we will need to use in our application. After this let's add the WordCount class:
public class WordCount { public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> { private final static IntWritable one = new IntWritable(1); private...