How to calculate Maximum salary of the employee with the name using the Map Reduce Technique

+2 votes
Suppose i have file in HDFS with the below

EmpId,EmpName,Dept,Salary,

121,raj,Dept1,8000
122,Kiran,Dept2,6000
123,John,Dept3,9000

Using mapreduce i want to get only the max salary of employee and his name

i was able to get the max salary but not able to get the name.. I am able to get only the max salary by keeping the empty key in map class and Math.max() in reducer class, so that  I am able to get only max salary. when i keep the key as emp name then it is displaying all the salaries of unique employees.
Jul 25, 2018 in Big Data Hadoop by Neha
• 6,140 points
194 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Please try the below code and it might help you to get the required outputdown vpls try the following code. you will get the results.

public static class Mymap extends Mapper<LongWritable,Text,Text,Text>    
 {  
  public void map(LongWritable k,Text v, Context con)throws IOException, InterruptedException  
  {  
   String line = v.toString();  
   String[] w=line.split(",");  
   int sal=Integer.parseInt(w[3]);  
   string name=Integer.parseInt(w[1]);
   con.write(new Text(name), new Text(name+","+sal));  
   }  
 } 

 public static class MyRed extends Reducer<Text,Text,IntWritable,Text>  
 {  
  public void reduce(Text k, Iterable<Text> vlist, Context con)
  throws IOException , InterruptedException  
     {  
      int max=0;  
      for(Text v:vlist)  
   {
        String line = v.toString();  
        String[] w=line.split(",");  
        int sal=Integer.parseInt(w[1]); 
        max=Math.max(max, sal);
   }  
   con.write(new IntWritable(max), k);  
  }

 }

answered Jul 25, 2018 by Neha
• 6,140 points

Related Questions In Big Data Hadoop

0 votes
1 answer

How to set the number of Map & Reduce tasks?

The map tasks created for a job ...READ MORE

answered Apr 18, 2018 in Big Data Hadoop by Shubham
• 12,150 points
39 views
0 votes
1 answer

Hadoop: How to get the column name along with the output in Hive?

You can get the column names by ...READ MORE

answered Nov 20, 2018 in Big Data Hadoop by Omkar
• 65,850 points
73 views
0 votes
1 answer

How to get started with Hadoop and do some development using Eclipse IDE?

Alright, there are couple of things that ...READ MORE

answered Apr 4, 2018 in Big Data Hadoop by Ashish
• 2,630 points
50 views
0 votes
1 answer

How to print the content of a file in console present in HDFS?

Yes, you can use hdfs dfs command ...READ MORE

answered Apr 19, 2018 in Big Data Hadoop by Shubham
• 12,150 points
250 views
0 votes
1 answer

Setting the Number of Map tasks and Reduce Tasks not Working

The command that you are running is ...READ MORE

answered May 3, 2018 in Big Data Hadoop by Ashish
• 2,630 points
88 views
0 votes
1 answer

How to change the replication factor of specific directory in Hadoop?

Yes, you can change the replication factor ...READ MORE

answered May 10, 2018 in Big Data Hadoop by Shubham
• 12,150 points
89 views
0 votes
1 answer

How to calculate number of slave nodes?

Total number of slave nodes in your ...READ MORE

answered Aug 16, 2018 in Big Data Hadoop by nitinrawat895
• 9,030 points
24 views
0 votes
1 answer

How to run Map Reduce program using Ubuntu terminal?

 I used the following steps to execute it ...READ MORE

answered Aug 7, 2018 in Big Data Hadoop by Neha
• 6,140 points
59 views
0 votes
1 answer

How to create a project for the first time in Hadoop.?

If you want to learn Hadoop framework ...READ MORE

answered Jul 26, 2018 in Big Data Hadoop by Neha
• 6,140 points
30 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.