Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- hh,0,Jeet,3000
- hk,1,Mayukh,4000
- nn,2,Antara,3500
- mm,3,Shubu,6000
- ii,4,Parsi,8000
- Antara -2147483648
- Mayukh -2147483648
- Parsi 3500
- Shubu 4000
- public class SecondHigestMapper extends Mapper<LongWritable,Text,Text,Text>{
- private Text salary = new Text();
- private Text name = new Text();
- public void map(LongWritable key,Text value,Context context) throws IOException, InterruptedException{
- if(key.get()!=0){
- String split[]= value.toString().split(",");
- salary.set(split[2]+";"+split[3]);
- name.set("ignore");
- context.write(name,salary);
- }
- }
- }
- public class SecondHigestReducer extends Reducer<Text,Text,Text,IntWritable>{
- public void reduce(Text key,Iterable<Text> values,Context context) throws IOException, InterruptedException{
- int highest = 0;
- int second_highest = 0;
- int salary;
- for(Text val:values){
- String[] fn = val.toString().split("\;");
- salary = Integer.parseInt(fn[3]);
- if(highest < salary){
- second_highest = highest;
- highest =salary;
- } else if(second_highest < salary){
- second_highest = salary;
- }
- }
- context.write(new Text(key),new IntWritable(second_highest));
- }
- }
- public class SecondHigestDriver {
- public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
- Configuration conf = new Configuration();
- Job job = new Job(conf,"Second Higest Sal");
- job.setJarByClass(SecondHigestDriver.class);
- job.setMapperClass(SecondHigestMapper.class);
- job.setCombinerClass(SecondHigestReducer.class);
- job.setReducerClass(SecondHigestReducer.class);
- job.setOutputKeyClass(Text.class);
- job.setOutputValueClass(IntWritable.class);
- FileInputFormat.addInputPath(job, new Path(args[0]));
- FileOutputFormat.setOutputPath(job, new Path(args[1]));
- System.exit(job.waitForCompletion(true) ? 0 : 1);
- }
- }
- name.set("ignore"); // Could use a NullWritable
- salary.set(split[2]+";"+split[3])); // change to TextWritable
- context.write(name,salary); // need to change the signature of the map method
Add Comment
Please, Sign In to add comment