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,300 points
5,647 views

1 answer to this question.

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,300 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
• 13,490 points
1,922 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 21, 2018 in Big Data Hadoop by Omkar
• 69,220 points
4,885 views
0 votes
1 answer

How to Change the maximum number of cells of a column family?

Hey, Given below is the syntax to change ...READ MORE

answered May 24, 2019 in Big Data Hadoop by Gitika
• 65,770 points
1,485 views
0 votes
1 answer

How to Modify the Maximum Number of Versions for a Column Family in Hbase?

Hey, The example uses HBase Shell to keep ...READ MORE

answered May 31, 2019 in Big Data Hadoop by Gitika
• 65,770 points
3,608 views
0 votes
1 answer

How to get the column name printed in a file along with the output in Hive?

Hi @Neethu, Regarding your query, I would suggest ...READ MORE

answered Jul 2, 2020 in Big Data Hadoop by Gitika
• 65,770 points
1,015 views
0 votes
1 answer

How to check the name of the hadoop server?

Hi@akhtar, If you're running a pseudo-distributed setup, you ...READ MORE

answered Oct 13, 2020 in Big Data Hadoop by MD
• 95,460 points
2,443 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,650 points
2,126 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,300 points
4,079 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 27, 2018 in Big Data Hadoop by Neha
• 6,300 points
1,161 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP