Guest User

Untitled

a guest
Jul 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. // kate: space-indent on; indent-width 2; mixedindent off; indent-mode cstyle;
  2.  
  3. package org.verificatum;
  4.  
  5. import java.io.IOException;
  6. import java.util.StringTokenizer;
  7.  
  8. import org.apache.hadoop.conf.Configuration;
  9. import org.apache.hadoop.fs.Path;
  10. import org.apache.hadoop.io.IntWritable;
  11. import org.apache.hadoop.io.ArrayWritable;
  12. import org.apache.hadoop.io.Text;
  13. import org.apache.hadoop.mapreduce.Job;
  14. import org.apache.hadoop.mapreduce.Mapper;
  15. import org.apache.hadoop.mapreduce.Reducer;
  16. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  17. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  18. import org.apache.hadoop.util.GenericOptionsParser;
  19.  
  20. public class Verificatum {
  21.  
  22. public static class PowMapper
  23. extends Mapper<Object, ArrayWritable<IntWritable>, IntWritable, IntWritable>{
  24.  
  25. private final static IntWritable one = new IntWritable(1);
  26. private IntWritable result = new IntWritable(1);
  27.  
  28. public void map(Object key, ArrayWritable<IntWritable> value, Context context
  29. ) throws IOException, InterruptedException {
  30. StringTokenizer itr = new StringTokenizer(value.toString());
  31. while (itr.hasMoreTokens()) {
  32. IntWritable[] valueArray = value.get();
  33. result.set(valueArray[0] * valueArray[1]);
  34. context.write(result, one);
  35. }
  36. }
  37. }
  38.  
  39.  
  40. public static void main(String[] args) throws Exception {
  41. Configuration conf = new Configuration();
  42. String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
  43. if (otherArgs.length != 2) {
  44. System.err.println("Usage: verificatum <in> <out>");
  45. System.exit(2);
  46. }
  47. Job job = new Job(conf, "verificatum");
  48. job.setJarByClass(Verificatum.class);
  49. job.setMapperClass(VerificatumMapper.class);
  50. // job.setCombinerClass(VerificatumMapper.class);
  51. // job.setReducerClass(VerificatumMapper.class);
  52. job.setOutputKeyClass(IntWritable.class);
  53. job.setOutputValueClass(IntWritable.class);
  54. FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
  55. FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
  56. System.exit(job.waitForCompletion(true) ? 0 : 1);
  57. }
  58. }
Add Comment
Please, Sign In to add comment