Abinitio Question #13 | Rank() function implementation in Abinitio
Watch my YouTube video for explanation :
Please look into the class notes here for your references:
SELECT deptno,
ename,
sal,
RANK() OVER (PARTITION BY deptno ORDER BY sal) "rank"
FROM emp
WHERE deptno = 30;
DEPTNO ENAME SAL rank
---------- ---------- ---------- ----------
30 JAMES 950 1
30 WARD 1250 2
30 MARTIN 1250 2
30 TURNER 1500 4
30 ALLEN 1600 5
30 BLAKE 2850 6
20
20
Can you achive it in Abinitio?
Input -> SORT (Key = DEPTNO,SAL ASC) ->SCAN -> Output
InputDML-
record
string(",") DEPTNO;
string(",") ENAME;
decimal(",") SAL;
decimal("\n") RANK;
end;
type temporary_type=
begin
decimal(",") prv_amt;
decimal(",") ranking;
decimal(",") ranking_tracking;
end;
temp::initialize(in)=
begin
temp.ranking::1;
temp.prv_amt::in.SAL;
temp.ranking_tracking::0;
end;
out::scan(temp,in)=
begin
out.ranking::if(in.SAL>temp.prv_amt) temp.ranking_tracking +1 else temp.ranking;
out.prv_amt::in.SAL;
out.ranking_tracking:: temp.ranking_tracking +1;
end;
out::finalize(temp,in)=
begin
out.*::in.*;
out.RANK::temp.ranking;
end;
OutputDML-
record
string(",") DEPTNO;
string(",") ENAME;
decimal(",") SAL;
decimal("\n") RANK;
end;
Fore more Abinitio, AWS and data engineering videos please subscribe , view , like and share my YouTube channel
Click DataPundit
Comments
Post a Comment