Print Minimum & Maximum Salary of Respective Employee

I have an input file in the below format :
NAME SAL
---- ---
A 4000
B 3000
C 8000
A 2000
B 7000
C 5000
B 2000
C 9000
A 1000

If I will use Sort ---> Aggregator Group by then it will give 3 columns like NAME,MAX(),MIN()
NAME MAX() MIN()
---- ----- -----
A 4000 1000

But my requirement is to generate the output which will give the maximum & minimum salary in a single col w.r.t the employees.Like below :
NAME SAL(Sal column will contain only minimum and maximum salary for respective employees)
NAME SAL
---- ---
A 4000
A 1000
B 7000
B 2000
C 9000
C 5000

Questions by Aloka   answers by Aloka

Showing Answers 1 - 18 of 18 Answers

Nick

  • Aug 6th, 2016
 

Use separate agg stage for Min and Max. Then Funnel the two outputs and sort by name.

  Was this answer useful?  Yes

shibiya joseph

  • Oct 24th, 2016
 

First we have to use two rollup function for min and max then concatenate the two outputs and sort by name.

  Was this answer useful?  Yes

Anil

  • Oct 25th, 2016
 

A) SeqFile --> Copy ----> Remove duplicate1 for Minimum sal - Peek1
|
|
v
Remove duplicate2 for Maximim sal - Peek2

1.In remove duplicate stages, take Name as Key, Partiton and sort by Name, Sal in Ascending order
2.In Remove duplicate1, use retain first value to get minimum value.
3.In Remove duplicate2, use retain last value to get maximum value.

  Was this answer useful?  Yes

VINAY YADAV

  • Dec 14th, 2016
 

Could you please elaborate your answer

  Was this answer useful?  Yes

Neha

  • Apr 7th, 2017
 

Use Seq File->Aggregator Stage (group by Salary, Emp_Name and find min, max salary)->use Pivot(horizontal Pivot)

  Was this answer useful?  Yes

Sirisha d

  • Apr 18th, 2017
 

Job Design :
Sequential File --> Aggregator --> Transformer --> Sequential File
Aggregator :
Group by - EmpName
Col for Calculation - Salary
Generate two columns - one for maximum salary (Max()) and one for minimum salary (min())
Hash partitioning and sort by EmpName
Transformer :
Define 2 loop variables.
LoopVar1 - Input col(EmpName)
LoopVar2 - If @ITERATION=1 Then Max_Sal Else Min_Sal
In the Loop While condition, give @ITERATION>0 and @ITERATION<=2
In the transformer output link,
assign LoopVar2 to Salary column.
This gives the minimum and maximum salary of an employee in separate rows in the same column.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions