Guest User

Untitled

a guest
Jun 24th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. hh,0,Jeet,3000
  2. hk,1,Mayukh,4000
  3. nn,2,Antara,3500
  4. mm,3,Shubu,6000
  5. ii,4,Parsi,8000
  6.  
  7. Antara -2147483648
  8. Mayukh -2147483648
  9. Parsi 3500
  10. Shubu 4000
  11.  
  12. public class SecondHigestMapper extends Mapper<LongWritable,Text,Text,Text>{
  13.  
  14. private Text salary = new Text();
  15. private Text name = new Text();
  16. public void map(LongWritable key,Text value,Context context) throws IOException, InterruptedException{
  17.  
  18. if(key.get()!=0){
  19. String split[]= value.toString().split(",");
  20. salary.set(split[2]+";"+split[3]);
  21. name.set("ignore");
  22. context.write(name,salary);
  23. }
  24. }
  25. }
  26.  
  27.  
  28. public class SecondHigestReducer extends Reducer<Text,Text,Text,IntWritable>{
  29.  
  30. public void reduce(Text key,Iterable<Text> values,Context context) throws IOException, InterruptedException{
  31. int highest = 0;
  32. int second_highest = 0;
  33. int salary;
  34.  
  35. for(Text val:values){
  36. String[] fn = val.toString().split("\;");
  37. salary = Integer.parseInt(fn[3]);
  38.  
  39. if(highest < salary){
  40. second_highest = highest;
  41. highest =salary;
  42. } else if(second_highest < salary){
  43. second_highest = salary;
  44. }
  45. }
  46. context.write(new Text(key),new IntWritable(second_highest));
  47.  
  48. }
  49.  
  50. }
  51.  
  52. public class SecondHigestDriver {
  53.  
  54. public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
  55. Configuration conf = new Configuration();
  56. Job job = new Job(conf,"Second Higest Sal");
  57. job.setJarByClass(SecondHigestDriver.class);
  58. job.setMapperClass(SecondHigestMapper.class);
  59. job.setCombinerClass(SecondHigestReducer.class);
  60. job.setReducerClass(SecondHigestReducer.class);
  61. job.setOutputKeyClass(Text.class);
  62. job.setOutputValueClass(IntWritable.class);
  63. FileInputFormat.addInputPath(job, new Path(args[0]));
  64. FileOutputFormat.setOutputPath(job, new Path(args[1]));
  65. System.exit(job.waitForCompletion(true) ? 0 : 1);
  66.  
  67. }
  68. }
  69.  
  70. name.set("ignore"); // Could use a NullWritable
  71. salary.set(split[2]+";"+split[3])); // change to TextWritable
  72. context.write(name,salary); // need to change the signature of the map method
Add Comment
Please, Sign In to add comment