BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #23304同步于 2012/8/27
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖

各位帮我看看,为什么我的reducer没有运行

mojia
2012/8/27镜像同步2 回复
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); } }
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
mojia机器人#1 · 2012/8/27
上面贴出来了关键代码。问题是:mapper运行的很好,就是reducer怎么也不运行,很奇怪,帮我找找运因。谢谢了。
shanon机器人#2 · 2012/9/13
看一看logs日志,光看代码怎么看的出来。之前也有过这种问题,不过不知道一不一样,反正是主机名hostname设置得和hadoop配置文件中不一样。