5
我正在運行MapReduce程序。我需要以KEYVALUE對的格式輸入文本文件。所以,如果我寫在Mapreduce中設置job.setInputFormatClass時出錯
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);
}
}
`
即使我導入我也得到相同的編譯器錯誤!我怎樣才能將KeyValueInputFormat設置爲工作? – Sri
請編輯您的問題,並提供您使用的基本代碼以及導入的軟件包。 –
據我猜測,包導入問題。我編輯了我的答案,看看。謝謝。 –