返回信息流package com.mojia.mr.demo;
import java.io.IOException;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
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 EarthQuakesMR {
static class MyMapper extends Mapper<LongWritable, Text, Text, IntWritable> {
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
System.out.println("running mapper...");
Parser parser = new Parser(value.toString());
String year = parser.getYear();
if (parser.isBig()) {
context.write(new Text(year), new IntWritable(1));
}
}
}
static class MyReducer extends
Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterable<IntWritable> values,
Context context) throws IOException, InterruptedException {
System.out.println("running reducer...");
int count = 0;
for (IntWritable value : values) {
count++;
}
System.out.println("[" + key + "," + 1 + "]");
context.write(key, new IntWritable(count));
}
}
public static void main(String[] args) throws IOException,
InterruptedException, ClassNotFoundException {
Job job = new Job();
job.setJarByClass(EarthQuakesMR.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.setMapperClass(MyMapper.class);
job.setReducerClass(MyReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
这是一条镜像帖。来源:北邮人论坛 / java / #23304同步于 2012/8/27
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
各位帮我看看,为什么我的reducer没有运行
mojia
2012/8/27镜像同步2 回复
订阅后,新回复会通过你的通知中心匿名送达。