SHARE
TWEET

Untitled

a guest May 19th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import org.apache.hadoop.conf.Configured;
  2. import org.apache.hadoop.fs.Path;
  3. import org.apache.hadoop.io.IntWritable;
  4. import org.apache.hadoop.io.Text;
  5. import org.apache.hadoop.mapreduce.Job;
  6. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  7. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  8. import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
  9. import org.apache.hadoop.util.Tool;
  10. import org.apache.hadoop.util.ToolRunner;
  11.  
  12. public class WordCount extends Configured implements Tool{
  13.      
  14.     public static void main(String[] args) throws Exception{
  15.         int exitCode = ToolRunner.run(new WordCount(), args);
  16.         System.exit(exitCode);
  17.     }
  18.  
  19.     public int run(String[] args) throws Exception {
  20.         if (args.length != 2) {
  21.             System.err.printf("Usage: %s needs two arguments, input and output    
  22. files\n", getClass().getSimpleName());
  23.             return -1;
  24.         }
  25.      
  26.         Job job = new Job();
  27.         job.setJarByClass(WordCount.class);
  28.         job.setJobName("WordCounter");
  29.          
  30.         FileInputFormat.addInputPath(job, new Path(args[0]));
  31.         FileOutputFormat.setOutputPath(job, new Path(args[1]));
  32.      
  33.         job.setOutputKeyClass(Text.class);
  34.         job.setOutputValueClass(IntWritable.class);
  35.         job.setOutputFormatClass(TextOutputFormat.class);
  36.          
  37.         job.setMapperClass(MapClass.class);
  38.         job.setReducerClass(ReduceClass.class);
  39.      
  40.         int returnValue = job.waitForCompletion(true) ? 0:1;
  41.          
  42.         if(job.isSuccessful()) {
  43.             System.out.println("Job was successful");
  44.         } else if(!job.isSuccessful()) {
  45.             System.out.println("Job was not successful");          
  46.         }
  47.          
  48.         return returnValue;
  49.     }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top