Java 和 Hadoop : Incompatible types with TextInputFormat

标签 java hadoop extending

我正在使用 hadoop 核心 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 而不是 InputFormat 的类。

但我相信 FileInputFormat 扩展了 InputFormat,因为我在声明中看到

public abstract class FileInputFormat<K extends Object, V extends Object> extends InputFormat<K, V>

我收到此错误的原因是否正确?还是我完全错了,通过将正确类(class)扩展到任何第 n 个学位的类(class)是有效的吗?

我是 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。

关于Java 和 Hadoop : Incompatible types with TextInputFormat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23329652/

相关文章:

JavaFX - 数据绑定(bind) - 添加附加 BooleanBinding

java - Android 喜欢 Toast in Swing

eclipse - 线程 "main"java.lang.NoClassDefFoundError : com/google/common/base/Preconditions 中的异常

datetime - 如何使用 mapreduce 和 pyspark 查找某年某一天的频率

hadoop - Hive中HWI和 "HiveServer"的区别

json - 使用 JQuery AJAX 预过滤器检查响应数据并有条件转发到 'Error' 事件处理程序

C++ 界面风格编程。需要一条出路

java - Java中引用父类

java - Toast 和 android 生命周期

reactjs - 扩展 Material UI 现有的深色模式颜色