Hadoop - 映射器和缩减器的@Override错误

时间:2016-10-10 03:47:35

标签: java hadoop mapreduce override reduce

我一直致力于MapReduce计划,但我遇到了障碍,需要一些帮助。我有一个运行3个作业的程序(作业#2在for循环中运行5次)似乎我的一些mappers和reducer没有正确定义。在编译时,我继续得到"方法不会覆盖或实现超类型的方法"错误。

这是我的计划的基本结构:

Job 1:

FirstMapper
没有减速机

Job 2:

第二个映射器
第一减速机

Job 3:

最终映射器
最终减速机

以下是我如何定义映射器和缩减器:

public static class FirstMapper extends Mapper<Object, Text, LongWritable, Vertex>  {
        @Override
        public void map(Object key, Text value, Context context) throws IOException, InterruptedException {}


public static class SecondMapper extends Mapper<LongWritable, Vertex, LongWritable, Vertex> {
        @Override
        public void map(long key, Vertex value, Context context) throws IOException, InterruptedException {}


public static class FirstReducer extends Reducer<LongWritable, Vertex, LongWritable, Vertex> {
        @Override
        public void reduce(Long key, Iterable<Vertex> values, Context context) throws IOException, InterruptedException {}


public static class FinalMapper extends Mapper<LongWritable, Vertex, LongWritable, LongWritable> {
        @Override
        public void map(Long key, Vertex value, Context context) throws IOException, InterruptedException {}


public static class FinalReducer extends Reducer<LongWritable, LongWritable, LongWritable, LongWritable> {
        @Override
        public void reduce(Long key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {}

FirstMapper 似乎没问题,因为它不会导致错误,但其他4个错误,我无法找出原因,因为方法签名看起来正确。我最初认为可能是因为我的自定义 Vertex 类,但是它实现了 Writable ,因此我不确定为什么会导致问题。任何和所有的帮助将不胜感激。感谢

1 个答案:

答案 0 :(得分:1)

您的密钥需要实现WritableComparable接口并匹配您在类MapperReducer签名中指定的类型。例如,在第二个中你有:

Mapper<LongWritable, Vertex, LongWritable, Vertex>

然后在map方法中使用long。这需要匹配您在签名中指定的类型,即LongWritable。因此第二张地图的参数需要如下所示:

map(LongWritable key, Vertex value, Context context)

所有最后四个课都有这个问题。