运行简单hadoop map/reduce教程

cl25kdpy  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(257)

你知道为什么简单的hadoopmap/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>

我在别处看到过,这可能是由于在项目中使用过时的hadoopjar文件造成的。我使用的是最新的稳定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.*;
eqoofvh9

eqoofvh91#

请检查一下你们的进口商品。也许您在程序中混合了新旧api。另外,我建议您使用新的api,即mapreduce而不是mapred。
hth公司

相关问题