Hadoop - 映射器和缩减器的@Override 错误
Hadoop - @Override error for mappers and reducers
我一直在研究 MapReduce 程序,但遇到了障碍,需要一些帮助。我有一个运行 3 个作业的程序(作业 #2 在 for 循环中得到 运行 5 次),似乎我的一些映射器和缩减器没有正确定义。编译后我不断收到 "method does not override or implement a method from a supertype" 错误。
这是我的程序的基本结构:
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 class 但它实现了 Writable 所以我不确定为什么会这样引起问题。任何和所有帮助将不胜感激。谢谢
您的密钥需要实现 WritableComparable
接口并匹配您在 类 Mapper
和 Reducer
签名中指定的类型。例如在第二个你有:
Mapper<LongWritable, Vertex, LongWritable, Vertex>
但随后在 map
方法中使用 long
。这需要匹配您在签名中指定的类型,即LongWritable
。所以第二张地图的参数需要看起来像:
map(LongWritable key, Vertex value, Context context)
后四个类都有这个问题。
我一直在研究 MapReduce 程序,但遇到了障碍,需要一些帮助。我有一个运行 3 个作业的程序(作业 #2 在 for 循环中得到 运行 5 次),似乎我的一些映射器和缩减器没有正确定义。编译后我不断收到 "method does not override or implement a method from a supertype" 错误。
这是我的程序的基本结构:
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 class 但它实现了 Writable 所以我不确定为什么会这样引起问题。任何和所有帮助将不胜感激。谢谢
您的密钥需要实现 WritableComparable
接口并匹配您在 类 Mapper
和 Reducer
签名中指定的类型。例如在第二个你有:
Mapper<LongWritable, Vertex, LongWritable, Vertex>
但随后在 map
方法中使用 long
。这需要匹配您在签名中指定的类型,即LongWritable
。所以第二张地图的参数需要看起来像:
map(LongWritable key, Vertex value, Context context)
后四个类都有这个问题。