我和我的MapReduce代码的麻烦。我的代码将写入最大高股票和相应的名称从输入到输出文件。问题是正在写零字节,并且在输出中得到一个空文件。的Hadoop没有书面方式输出到文件
HighestStock.java
JobConf conf = new JobConf(HighestStock.class);
conf.setJobName("Highest Stock");
FileInputFormat.addInputPath(conf, new Path(args[0]);
FileOutputFormat.setOutputPath(conf, new Path(args[1]);
conf.setMapperClass(HighStockMapper.class);
conf.setReducerClass(HighStockReducer.class);
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
JobClient.runJob(conf);
HighStockMapper.java
public class HighStockMapper implements Mapper<LongWritable, Text, Text, IntWritable> {
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String line = value.toString();
String[] tokens = line.split(",");
String name = tokens[0];
int high = (int) Double.parseDouble(tokens[3]);
context.write(new Text(name), new IntWritable(high);
}
HighStockReducer.java
public class HighStockReducer extends MapReduceBase
implements Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce (Tex key, Iterator<IntWritable> values,
OutputCollector<Text, IntWritable> output, Reporter reporter)
throws IOExceptiion {
int maxValue = Integer.MIN_VALUE;
while (values.hasNext()) {
maxValue = Math.max(maxValue, values.next().get());
}
output.collect(key, new IntWritable(maxValue));
}
}
任何帮助调试这将非常感谢!
截图命令行的结果
是啊,我是从我的虚拟机重新键入这一点,因为它不会让我来回拷贝。我要发表新评论(上面这个帖子找到)用的,当我编译 – 2014-09-26 02:28:03
后,您在混合新的Hadoop API和旧的API运行它,我得到什么的截图,在映射您使用context.write和减速您使用的输出.collect有没有特别的原因? – user3484461 2014-09-26 06:16:36
没有特别的原因,我是立足我的代码关闭的旧代码,我在GitHub上发现这可能就是为什么有一些不一致的地方。我该怎么改变,以便mapper和reducer api的匹配? – 2014-09-26 13:26:47