【问题标题】:MapReduce with extended objects as Key for reducerMapReduce 扩展对象作为 reducer 的 Key
【发布时间】:2014-04-03 12:31:46
【问题描述】:

我正在尝试使用这样的自定义对象来实现 map 和 reduce:

映射器:

public class SommeMapper extends Mapper<LongWritable, Text, Entity, Entity>

减速机:

public class SomeReducer extends Reducer<Entity,Entity, NullWritable, Text>

虽然我有三个对象作为可以进入减速器的 Key:

Entity implements WitableComparable

A extends Entity

B extends Entity

当我用 A 或 B 打电话给 Context.write

我收到以下错误:

java.io.IOException: Type mismatch in key from map: expected Entity, recieved A

如果我可以在 Keys 中使用 inmhertance 来减少,有人可以指出吗?

【问题讨论】:

  • 在映射器类中转换为Entity后尝试添加A和B。

标签: java hadoop mapreduce


【解决方案1】:

您必须在创建作业期间为您的映射器定义输出键/值类:

conf.setOutputKeyClass(Entity.class);
conf.setOutputValueClass(Entity.class);

【讨论】:

  • 谢谢,已经做了。最终以研究 hadoop 代码结束。看起来你不能传递除了你声明的任何其他对象,即使它是从它扩展而来的。
  • 是的,你可以:如果你定义 org.apache.hadoop.hbase.client.Mutation 作为输出,你可以同时写 Put 和 Delete,所以我认为你可以这样做
【解决方案2】:

您是否考虑过为 A 和 B 创建一个包装类? C类{A val1;乙 val2; } 或 C 类 {Entity val;}

【讨论】:

  • 这正是我所做的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-27
  • 2013-04-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多