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,280 points
427 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,280 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,290 points
68 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
• 67,480 points
245 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 in Big Data Hadoop by Gitika
• 25,340 points
20 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 in Big Data Hadoop by Gitika
• 25,340 points
36 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
94 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
• 13,290 points
494 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
131 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,280 points
94 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,280 points
70 views