我正在使用hadoop core 0.20.2,并且在尝试为我的工作设置输入格式时遇到类型不兼容的问题。我只是想让一个简单的wordcount程序运行。
这是我的主要方法:
public static void main(String[] args) throws Exception{
JobConf conf = new JobConf(Wordcount.class);
conf.setJobName("wordcount");
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
conf.setMapperClass(Map.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);
}
在线上conf.setInputFormat(TextInputFormat.class);
我遇到了一个错误incompatible types class<TextInputFormat> cannot be converted to Class<? extends InputFormat>
当我看一下setInputFormat方法时,我看到:
public void setInputFormat(Class<? extends InputFormat> theClass) {
}
虽然我不是100%知道我的Class<? extends InputFormat> theClass
意思是什么,但我必须传递一个扩展InputFormat的类。如果我走错了路,请告诉我。
因此,当我看一下TextInputFormat类时,我会看到:
public class TextInputFormat extends FileInputFormat<LongWritable, Text>
所以我要传递一个扩展FileInputFormat和NOT InputFormat的类。
但是我相信FileInputFormat扩展了InputFormat,因为我在声明中看到了
public abstract class FileInputFormat<K extends Object, V extends Object> extends InputFormat<K, V>
我对我为什么收到此错误的理解正确吗?还是我完全错了,并且通过了将正确的课程扩展到第n级的课程是有效的吗?
我对Java还是相当陌生,甚至对Hadoop还是比较新。我想指出的是,我在线路上也遇到了错误
FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
读为“不兼容的类型:JobConf无法转换为Job”。我知道0.20.2不是Hadoop的最新版本,但我必须使用该版本。在新版本的Hadoop中,我遇到了其他创建作业配置的方法,并且开始认为自己遇到了问题,因为我可能正在引用在0.20.2之后添加的类。
我正在阅读在线资源以帮助获得工作副本,但是我永远不知道所使用的版本。因此,我现在的代码可能不匹配。任何帮助将不胜感激。
看一看这些类来自的包。您应该使用一组将“ mapred”作为一个级别的软件包,或另一组将“ mapreduce”作为一个级别的软件包。我怀疑您正在混合软件包,并且需要使用其他软件包中的TextInputFormat。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句