java - 运行简单的Hadoop Map/Reduce教程

标签 java hadoop

任何简单的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.*;

最佳答案

请检查一次您的进口。也许您在程序中混合了新旧API。另外,我建议您使用新的API,即 mapreduce 而不是 mapred

高温超导

关于java - 运行简单的Hadoop Map/Reduce教程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18080102/

相关文章:

java - 将 java -version 的结果打印到文件 -> 为什么结果文件为空?

java - 安卓5.1 : Attempt to write to field 'java.util.ArrayList android.animation.AnimatorSet$Node.nodeDependents' on a null object reference

Java - JFrame 关闭时如何打印消息?

hadoop - 如何限制映射缩减作业中发送到缩减程序的记录数量?

hadoop - 哪个更快?带有 Where 子句的 Spark SQL 或在 Spark SQL 之后在 Dataframe 中使用过滤器

performance - 使用Hive/Hadoop连接两个排序的文件

java - Java 中对象的实例,奇怪的行为

java - 如何使用 Apache MINA 库编写 SFTP 客户端

java - 当我尝试在 Apache Mahout 中运行示例时,此错误告诉我们什么?

hadoop - 如何在 HBase 上配置 map reduce jobs