代写代考 import java.io.IOException;

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;

Copyright By PowCoder代写 加微信 powcoder

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class WordCount {

public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, “word count”);
job.setJarByClass(WordCount.class);
job.setMapperClass(WordCountMapper.class);
job.setCombinerClass(WordCountReducer.class);
job.setReducerClass(WordCountReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);

public static class WordCountMapper extends Mapper
private final static IntWritable one = new IntWritable(1);
private Text wordObject = new Text();

public void map(Object key, Text value, Context context)
throws IOException, InterruptedException {

String line = value.toString();
for (String word : line.split(“\\W+”)) {
if (word.length() > 0) {
wordObject.set(word.toLowerCase());
context.write(wordObject, one);

public static class WordCountReducer extends Reducer
private IntWritable wordCountWritable = new IntWritable();
public void reduce(Text key, Iterable values, Context context)
throws IOException, InterruptedException {
int wordCount = 0;
for (IntWritable value : values) {
wordCount += value.get();
wordCountWritable.set(wordCount);
context.write(key, wordCountWritable);

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com