java - 在 Mapreduce 中设置 job.setInputFormatClass 时出错

标签 java hadoop mapreduce

我正在运行一个 MapReduce 程序。我需要以 KEYVALUE 对的格式提供输入文本文件。这样如果我写

job.setInputFormatClass(KeyValueTextInputFormat.class);

eclipse 编译器显示错误,我无法使用 InputFormat。 无论如何我需要将输入的格式设置为 KeyValueTextInputFormat 我该怎么做呢 ??有什么想法吗?????

我的代码是

`

package com.iot.dictionary;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.KeyValueTextInputFormat;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;


import com.iot.dictionary.Dictionary.AllTranslationsReducer;
import com.iot.dictionary.Dictionary.WordMapper;
public class Driver2 {
public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
    Configuration conf = new Configuration();

        String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
        if (otherArgs.length != 2) {
          System.err.println("Usage: wordcount <in> <out>");
          System.exit(2);
        }
        Job job = new Job(conf, "dictionary");
        System.out.println("Job-> "+job.toString());
        job.setJarByClass(Dictionary.class);
        job.setMapperClass(WordMapper.class);
        job.setReducerClass(AllTranslationsReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);
        job.setInputFormatClass(KeyValueTextInputFormat.class);
        FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
        FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}

`

最佳答案

如果您使用新的 Hadoop API(Hadoop 0.20.2 及更高版本),则必须从包 org.apache.hadoop.mapreduce.lib.input.KeyValueTextInputFormat 导入 KeyValueTextInputFormat.class 类,如果您使用旧的Hadoop API,你必须从 org.apache.hadoop.mapred.KeyValueTextInputFormat 导入它

您在代码中看到了这一行:

import org.apache.hadoop.mapred.KeyValueTextInputFormat;

改成

import org.apache.hadoop.mapreduce.lib.input.KeyValueTextInputFormat;

希望这对您有所帮助。

谢谢

关于java - 在 Mapreduce 中设置 job.setInputFormatClass 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16958159/

相关文章:

java - 我需要解析字符串并提取信息以输入数据库

java - pentaho 5.2 中获取 olap4j 连接时出现异常

logging - 如何从我的 map/reduce 应用程序登录?

hadoop - 如何解决mapreduce中的平均问题?

hadoop - Apache Flume自定义拦截器-二进制和奇怪的HDFS文件

python - 设置 App Engine mapreduce 分片大小

java - 注入(inject)任务的 EJB 返回 UnsatisfiedResolutionException

java - Android App - 如何将 Canvas 上的位图绘图保存为图像?检查代码?

hadoop - pig 存储脚本失败

hadoop - amazon s3n 与 hadoop mapreduce 的集成不起作用