You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
1.2 KiB
29 lines
1.2 KiB
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.io.Intwritable;
|
|
import org.apache.hadoop.io.Text;
|
|
import org.apache.hadoop.mapreduce.Job;
|
|
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
|
|
import org.apache.hadoop.mapreduce.lib.output.File0utputFormat;
|
|
import org.apache.hadoop.util.GenericOptionsParser;
|
|
public class Wordcount {
|
|
public static void main(string[] args)throws Exception {
|
|
Configuration conf=new configuration();
|
|
String[] otherArgs =new GenericOptionsParser(conf, args).getRemainingArgs();
|
|
if(otherArgs.length<2){
|
|
System.err.println("Usage: wordcount <in>[<in>...] <out>");
|
|
System.exit(2);
|
|
}
|
|
Job job =Job.getInstance(conf, "word count");
|
|
job.setJarByclass(Wordcount.class);
|
|
job.setMapperclass(WordcountMapper.class);
|
|
job.setReducerclass(WordcountReducer.class);
|
|
job.setOutputKeyclass(Text.class);
|
|
job.setoutputValueclass(IntWritable.class);
|
|
for(int i e;i<otherArgs.length-1;++i){
|
|
FileInputFormat.addInputPath(job, new Path(otherArgs[i]));
|
|
}
|
|
FileOutputFormat.setOutputPath(job, new Path(otherArgs[otherArgs.length - 1]));
|
|
System.exit(job.waitForcompletion(true)?0:1);}
|
|
}
|