我正在运行MapReduce程序。我需要以KEYVALUE对的格式给出输入文本文件。所以,如果我写
job.setInputFormatClass(KeyValueTextInputFormat.class);
eclipse编译器显示错误,我无法使用InputFormat。 无论如何,我需要将Input的格式设置为KeyValueTextInputFormat 我该怎么做呢 ??任何IDea ?????
我的代码是
`
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);
}
}
`
答案 0 :(得分:10)
如果您正在使用新的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;
希望这有帮助。
由于