这个作业完成后,我将运行另一个具有身份映射器类[2]的作业,该作业将读取从先前作业执行生成的地图输出,并生成相同的地图输出。我已经在[3]中将身份映射器设置为作业,但我在[4]中得到了错误。
我认为这个问题的原因是setMapperClass(Class<? extends Mapper> cls)
来自不同类型的IdentityMapper
[5]。
我如何使用IdentityMapper
?
[1]第一份工作的地图类
public static class MyMap extends 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, Context context
) throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString());
while (itr.hasMoreTokens()) {
word.set(itr.nextToken());
context.write(word, one);
}
}
public void run(Context context) throws IOException, InterruptedException {
try {
while (context.nextKeyValue()) {
map(context.getCurrentKey(), context.getCurrentValue(), context);
}
} finally {
cleanup(context);
}
}
}
[2]身份等级:
public static class MyFullyIndentityMapper extends IdentityMapper<Text, IntWritable> {}
[3]我将身份类设置为映射器。
JobConf conf = new JobConf(MyWordCount.class);
conf.setJobName("wordcount");
conf.setClass("mapreduce.job.map.identity.class", MyFullyIndentityMapper.class, IdentityMapper.class);
Class<? extends IdentityMapper> identityClass = (Class<? extends IdentityMapper>) conf.getClass("mapreduce.job.map.identity.class", IdentityMapper.class);
job.setMapperClass(identityClass.asSubclass(Mapper.class));
[4]我得到的错误:
Output path: /output1
java.lang.ClassCastException: class org.apache.hadoop.mapred.examples.MyWordCount$MyFullyIndentityMapper
at java.lang.Class.asSubclass(Class.java:3404)
[5]身份映射器
public class IdentityMapper<K, V> extends MapReduceBase implements Mapper<K, V, K, V> {...}
答案 0 :(得分:1)
我不明白为什么你在下面的代码片段中使事情复杂化
JobConf conf = new JobConf(MyWordCount.class);
conf.setJobName("wordcount");
conf.setClass("mapreduce.job.map.identity.class", MyFullyIndentityMapper.class, IdentityMapper.class);
Class<? extends IdentityMapper> identityClass = (Class<? extends IdentityMapper>) conf.getClass("mapreduce.job.map.identity.class", IdentityMapper.class);
job.setMapperClass(identityClass.asSubclass(Mapper.class));
不要设置任何映射器类。
job.setMapperClass(identityClass.asSubclass(Mapper.class));
请注释掉上述内容。 MapReduce框架默认运行IdentityMapper。
以上是我对你的问题的理解。我可能误解了你的问题。