【问题标题】:Running simple Hadoop map/reduce tutorial运行简单的 Hadoop map/reduce 教程
【发布时间】:2013-08-06 12:24:47
【问题描述】:

任何想法为什么简单的 Hadoop map/reduce 教程会为我标记错误。这是代码,直接从 Apache 的教程中复制而来:

public class Mining {

public static class MapClass extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();

    public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
        String line = value.toString();
        StringTokenizer tokenizer = new StringTokenizer(line);
        while (tokenizer.hasMoreTokens()) {
            word.set(tokenizer.nextToken());
            output.collect(word, one);
        }
    }
}

public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
    public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
        int sum = 0;
        while (values.hasNext()) {
            sum += values.next().get();
        }
        output.collect(key, new IntWritable(sum));
    }
}

public static void main(String[] args) throws Exception {
    JobConf conf = new JobConf(Mining.class);
    conf.setJobName("wordcount");

    conf.setOutputKeyClass(Text.class);
    conf.setOutputValueClass(IntWritable.class);

    conf.setMapperClass(MapClass.class);
    conf.setCombinerClass(Reduce.class);
    conf.setReducerClass(Reduce.class);

    conf.setInputFormat(TextInputFormat.class);
    conf.setOutputFormat(TextOutputFormat.class);

    FileInputFormat.setInputPaths(conf, new Path(args[0]));
    FileOutputFormat.setOutputPath(conf, new Path(args[1]));

    JobClient.runJob(conf);
}
}   

错误是在编译时并且是:

The type Mapper is not generic; it cannot be parameterized with arguments <LongWritable, Text, Text, IntWritable>

我在其他地方读到过这可能是由于在您的项目中使用过时的 Hadoop jar 文件造成的。我正在使用最新的稳定 jar,hadoop-core-1.2,我也尝试过 0.20。关于问题出在哪里有什么建议吗?

编辑 - 进口清单:

import java.io.IOException;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*; 
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;

【问题讨论】:

标签: java hadoop


【解决方案1】:

请检查一次您的导入。也许您在程序中混合了新旧 API。另外,我建议您使用新的 API,即 ma​​preduce 而不是 ma​​pred

HTH

【讨论】:

  • 我现在已经包含了我的导入。所以你认为 mapred 是造成问题的原因吗?我尝试将 mapred 更改为 mapreduce,但现在所有扩展和实现部分都抱怨因为他们想要 mapred 版本
  • 会的。如果您想使用旧 API,请确保您没有从新 API 导入任何内容。
猜你喜欢
  • 2013-06-10
  • 1970-01-01
  • 2012-04-03
  • 2011-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-07
  • 1970-01-01
相关资源
最近更新 更多