Created
December 2, 2019 13:34
-
-
Save Andromelus/1f670288e69466c08f6743503564d771 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sdz.hadoop.wordcount; | |
import java.io.IOException; | |
import java.util.Iterator; | |
import org.apache.hadoop.conf.Configuration; | |
import org.apache.hadoop.conf.Configured; | |
import org.apache.hadoop.fs.FileSystem; | |
import org.apache.hadoop.fs.Path; | |
import org.apache.hadoop.io.Text; | |
import org.apache.hadoop.io.IntWritable; | |
import org.apache.hadoop.io.LongWritable; | |
import org.apache.hadoop.mapreduce.Job; | |
import org.apache.hadoop.mapreduce.Mapper; | |
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; | |
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; | |
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; | |
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; | |
import org.apache.hadoop.mapreduce.Reducer; | |
import java.util.StringTokenizer; | |
import org.apache.hadoop.util.GenericOptionsParser; | |
import org.apache.hadoop.util.Tool; | |
import org.apache.hadoop.util.ToolRunner; | |
public class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable> { | |
private IntWritable totalWordCount = new IntWritable(); | |
@Override | |
public void reduce(final Text key, final Iterable<IntWritable> values, | |
final Context context) throws IOException, InterruptedException { | |
int sum = 0; | |
Iterator<IntWritable> iterator = values.iterator(); | |
while (iterator.hasNext()) { | |
sum += iterator.next().get(); | |
} | |
totalWordCount.set(sum); | |
context.write(key, totalWordCount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment