System.err.println("Usage: wordcount [...] ");
System.exit(2);
}
Job job = Job.getInstance(conf, "word count");
job.setJarByClass(WordCountTask.class);
job.setMapperClass(WordCountMap.class);
job.setReducerClass(WordCountReduce.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileSystem fs = FileSystem.get(conf);
for (int i = 0; i < otherArgs.length - 1; i++) {
FileInputFormat.addInputPath(job, new Path(otherArgs[i]));
}
if(fs.exists(new Path(otherArgs[otherArgs.length - 1]))){
fs.delete(new Path(otherArgs[otherArgs.length - 1]));
}
FileOutputFormat.setOutputPath(job, new Path(otherArgs[(otherArgs.length - 1)]));
job.setNumReduceTasks(1);
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
6.提交:
?hadoop jar hadoop-examples.jar demo.wordcount(主類名) Dmapreduce.job.queuename=XX(系統(tǒng)參數(shù)) input output
?缺點:無定時調(diào)度
常用的InputFormat:
TextInputFormat key:行便宜 value:文本內(nèi)容,split計算:splitSize=max("mapred.min.split.size",min("mapred.max.split.size",blockSize)) mapred.min.split.size 在大量文本輸入的情況下,需要控制map的數(shù)量,可以調(diào)此選項。
CombineTextInputFormat(集群默認),多個小文件分片送到一個map中處理,主要解決多個小文件消耗map資源的問題。
sequenceFileInputFormat,采用自己的序列化方式,通常文件名為key,value為文件內(nèi)容,可在存儲上解決小文件對namenode的影響。