Guest User

Untitled

a guest
Dec 15th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. package com.isea.mapreduce;
  2.  
  3. import org.apache.hadoop.conf.Configuration;
  4. import org.apache.hadoop.fs.Path;
  5. import org.apache.hadoop.io.IntWritable;
  6. import org.apache.hadoop.io.Text;
  7. import org.apache.hadoop.mapreduce.Job;
  8. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  9. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  10.  
  11. import java.io.IOException;
  12.  
  13. public class WordCountDriver {
  14. public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
  15.  
  16. args = new String[]{"G:/input/input1/wordcount.txt","g:/output/output1"};
  17.  
  18. //获取Job的配置信息
  19. Configuration configuration = new Configuration();
  20.  
  21. //获取job
  22. Job job = Job.getInstance(configuration);
  23.  
  24. //设置jar包的加载路径
  25. job.setJarByClass(WordCountDriver.class);
  26.  
  27. //关联Mapper和Reducer的逻辑类
  28. job.setMapperClass(WordCountMapper.class);
  29. job.setReducerClass(WordCountReducer.class);
  30.  
  31. //设置Mapper的输出的key和value的类型
  32. job.setMapOutputKeyClass(Text.class);
  33. job.setOutputValueClass(IntWritable.class);
  34.  
  35. //设置最后的输出的key和value的类型
  36. job.setOutputKeyClass(Text.class);
  37. job.setOutputValueClass(IntWritable.class);
  38.  
  39. //设置输入输出路径
  40. FileInputFormat.setInputPaths(job,new Path(args[0]));
  41. FileOutputFormat.setOutputPath(job,new Path(args[1]));
  42.  
  43. boolean result = job.waitForCompletion(true);
  44. System.exit(result ? 0 : 1);
  45. }
  46. }
Add Comment
Please, Sign In to add comment