You are on page 1of 18

I have a src like 3 column

ID NAME ADDRS
1 A 73
1 A NAGAR
1 A CHENNAI

My req o/p is

ID NAME ADDRS
1 A 73 NAGAR CHENNAI

I am using one logiic but is not getting o/p clearly
1) group by both id and name
2) vportiiI(addrsprev,addrs,,vport, addrs)
3) prevaddrs
iI i am wrong correct and give some correct logic with screen shot.
the mapping Ilow should be like below.

SRC--~SQ--~SRT( By ID)--~EXP--~AGG--~TGT

In sorter sort data by ID.

in expression use below logic
input ports
inID
inNAME

Variable ports

vNAMEIIF(vIDinID,vNAME,,inNAME,inNAME)
vIDinID
outNAMEvNAME
in aggregator group by id create out put port
outNAMEMAX(NAME which is coming Irom expression)
Let me know iI Iurther details required.
When we sort the data using ID as key the order oI ADDR change how we can handle this ?

Eg. ADDR
Nagar
13
Chennai
For this we can't do any thing. But iI you have any identiIier in source to consider in order we
can use that one also in sort else based on date in source we can identiIy this.
In expression the port order should be like below.

inID
Inname
vADDRIIF(VID ID, VADDR ,,' ',,ADDRS, ADDRS)
vIDID
OADDRvADDR

so vID port should be aIter vADDR variable port.
No need to use aggregate Iunction (MAX Iun) in the above scenario. Justy pass OADDR to
downstream transIomation and group by ID.
Logic: Aggregator transIormation passes the last record oI each group by deIault.

2. I am Iinding diIIiculty in Iinding "Second Highest" salary using "Rank
Transformation", Where I apply Rank and then Filter based on Rank.
In below sample data - 4500 is second highest salary which shows Rank '3', hence unable to
apply logic Ior 2, and in general terms 5, etc...
RANK()

ID NAME SALARY RANK
===============================
1 Mukesh 5000 1
2 Suresh 5000 1
3 Ganesh 4500 3
4 Mahesh 4000 4
5 Rakesh 4000 4
6 Jitesh 3000 6


DENSE_RANK solves the purpose but we don't have this Iunction in InIormatica Tool.

DENSE_RANK()

ID NAME SALARY RANK
===============================
1 Mukesh 5000 1
2 Suresh 5000 1
3 Ganesh 4500 2
4 Mahesh 4000 3
5 Rakesh 4000 3
6 Jitesh 3000 4

Please help me Iinding out second highest salary, in this case and in general terms.

Try the below logic and let me know the outcome.

1) In the source DB Use order by Ior the salaray column (or) order by salary using Sorter
TransIormation.
2)Create the Iollowing port in the expression TX
Salary (inputport)
VRank IIF(Salary!VSalary,Vrank1,Vrank)
VSalary Salary
Output VRank
3)Then allow only the records which is having Rank 2 using Filter transIormation

SQ -~ Sorter -~ Exp -~ ......
In Expression TransIormation, I am using as given in screenshot.


Please correct, iI I am wrong.....
Please change the port order. like below....

vRank
vSAL
oSAL

I Iollowed the Port sequence (v_Rank, v_SAL, o_SAL) as mentioned.
Here oSAL is connected to Port (SAL) in Target Table.
But when I query the Target Table I am getting value ZERO (0).

Please help me understanding this.

Please try this

SRC--~SQ--~SRT--~EXP--~FIL--~TGT

SRC

EMPNO
ENAME
SAL

SQ--~
EMPNO
ENAME
SAL
SRT--~
EMPNO
ENAME
SAL
Here sort data by SAL
EXP--~

inEMPNO
inENAME
inSAL
create variable ports
vRANKIIF(inSALvPRESAL,vRANK,vRANK1)
vPRESALinSAL
Create out put port
outRANKvRANK
From expression take Iollowing ports to Iilter transIormation

inEMPNO
inENAME
inSAL
outRANK
Apply Iilter outRANK2
connect
inEMPNO
inENAME
inSAL
to target.
I am trying to Iind out second highest salary oI each department (10, 20, 30)
(See screenshot of SQL Plus of previous post).
Hence, I should get Iollowing rows in Target Table
EMPNO ENAME SAL

7782 CLARK 2450
7566 JONES 2975
7499 ALLEN 1600
I proceeded as per your suggestion (Filter was not aplied) and try to see the output in Target
Table. I Iound Rank Ior all the values.
Source --~ SQ --~ Sorter (EPTNO SC & SAL SC) --~ Exp (Your logic) --~ Target Table
What could be the reason Ior that?

rom the above example as per the mapping Ilow data will be like below
SRC--~SQ--~SRT--~EXP--~FIL--~TGT
at SRC and SQ
Data looks like below
ID NAME SALARY DEPT

1 Mukesh 5000 10
2 Suresh 5000 20
3 Ganesh 4500 30
4 Mahesh 4000 10
5 Rakesh 4000 20
6 Jitesh 3000 30
7 Mahesh 3000 10
8 Rakesh 3000 20
9 Jitesh 2000 30
AIter sorter data looks like blow
ID NAME SALARY DEPT

1 Mukesh 5000 10
4 Mahesh 4000 10
7 Mahesh 3000 10
2 Suresh 5000 20
5 Rakesh 4000 20
8 Rakesh 3000 20
3 Ganesh 4500 30
6 Jitesh 3000 30
9 Jitesh 2000 30

In expression Ior Iirst record
inEMPNO1
inENAMEMukesh
inDEPTNO10
inSAL5000
vRANKIIF(inDEPT~vPREDEPT,1,IIF(inSALvPRESAL,1,vRANK1)) Ior this
value calculation
inDEPT equal to 10 and vPREDEPT is 0 so condition true and it will return 1 , inthis
scenario it won't check Ior sal
vPREDEPT10 this value 10 will assign only aIter vRANK caluction so now
vPREDEPT10
vPRESAL5000
outRANK1

In the same way Ior second record

inEMPNO4
inENAMEMukesh
inDEPTNO10
inSAL4000
vRANKIIF(inDEPT~vPREDEPT,1,IIF(inDEPTvPRESAL,1,vRANK1))
inDEPT is equal to vPREDEPT so the condition inDEPT~vPREDEPT Ialse and it will
go to second iI statement, inSALvPRESAL(40005000) this condition Ialse so
vRANK1112.
vPREDEPT10
vPRESAl4000
outRANK2
like this.......
Iinal out put Irom expression is like below
ID NAME SALARY DEPT RANK

1 Mukesh 5000 10 1
4 Mahesh 4000 10 2
7 Mahesh 3000 10 3
2 Suresh 5000 20 1
5 Rakesh 4000 20 2
8 Rakesh 3000 20 3
3 Ganesh 4500 30 1
6 Jitesh 3000 30 2
9 Jitesh 2000 30 3
InIilter RANK2 then out put Irom Iilter is
ID NAME SALARY DEPT RANK

4 Mahesh 4000 10 2
5 Rakesh 4000 20 2
6 Jitesh 3000 30 2
Please go through my mapping and correct me where I am going wrong....
Still I am getting Rank Value -
Mapping

Expression TransIormation properties: -


I will apply Filter TransIormation once I start getting correct Rank values....
Please change the port order in expression transIormation like below
inEMPNO
inENAME
inSAL
inDEPTNO
vRANKIIF(inDEPTNO~vDEPTNO,1,IIF(inSALvSAL,vRANK,vRANK1))
vSALinSAL
vDEPTNOinDEPTNO
oRANKvRANK
Actually inIormatica will process the ports in the Iollowing order
1) input port
2) Variable port as in the order
3) Output port

So in your logic you are suppose to check the DEPTNO and salaray oI the employee in iII
condition beIore the assignment oI VSAL and VDEPTNO.
Please change the port order as Veeru mentioned
Move the vDEPTNOinDEPTNO and vSALinSAL aIter the VRANK port
I was doing some mistake in Expression TransIormation. There I mentioned Expression as -
"v_RANKIIF......".
When I removed "v_RANK" it started working Iine.
Order oI the port as Iollows: - in_EMPNO, in_ENAME, in_EPTNO, in_SAL, v_RANK,
v_SAL, v_EPTNO, o_RANK
There was one mistake in the logic
IIF(in_EPT<>v_EPT,1,IIF(in_SALv_SAL,1,v_RANK+1)) which was suggested to me.
(See the output in Red Window)
I modiIied this logic to
IIF(in_EPTNO<>v_EPTNO,1,IIF(in_SALv_SAL,v_Rank,v_Rank+1)) and got the
result what I wanted. (See the output in Green Window)



How can calculate the sum or average of salaries for each department without using aggregator
transformation in my mapping.

My source and target are files.
we can do this with the help oI variables in the expression transIrmation.

First step is to sort the data based on dept number.
In expression, add three variable ports and one output port -
vdept odept
idept input Irom prev transoIrmation~
odept vdept
vsal IIF(vdept idept, salvsal, sal)
outsal vsal
check iI the vdept idept, iI they are same then add the salaries. II there is a change in dept
number then replace the vsal with the sal.
Second step is to sort the data based on dept num,salaries in descending order. And in next
expression, use the same logic to pick the Iirst row(and Iilter all other rows Ior that dept
number).
In expression2, create 3 variable ports.
vdept odept
idept input Irom prev transoIrmation~
odept idept
FLAG IIF(vdept idept , 'N' , 'Y')
Finally Iilter all the rows with FLAG as "Y".
Let me know iI you need more details.
You can skip second step ie one EXP and sorter just by adding a rank trans. Select group by on
dept and rank based on column sumsal which is a output port in EXP1.
(by deIault rank will output TOP 1 row(sum oI sal) ) oI each dept.
4. I am newbie to inIormatica and need helps and suggestions on unknown dimension key.
- Should I use unknown dimension row or unknow dimension member?
- What is the diIIerence?
- Should i append unknow dimension row aIter each loading?
- Where can I Iind some documents related to it?
When you loading data in Fact tables usually we will do lookup on dimension to populate key
value in Fact tables. II you unable to Iind Fact value in Dimension table , depending on Business
logic you need to insert record in Fact table or reject. II you want to insert that record in Iact
table then you have to assign some deIault value to that record Ior this you need to insert one
deIault record in all dimension tables with UNKNOWN.
What is the best practice Ior inserting this deIault record in all dimension table?
Can I add one insert into dimtable1 (..) values(...) in pre-sql oI DIMTABLE1?
What is the best way to do this?
While creating dimension tables you can insert deIault records in all dimension tables one time
with -1 primary key and deIault 'UNKNOWN' values Ior all varchar attributes.
We will truncate dimension table every night so I cannot insert deIault record at the time
creating.
I want to insert this deIault record beIore we start loading operational data every night. What
should I do? store procedure? pre-sql?
How you are truncating tables? iI you are using procedure then use same procedure Ior inserting
records?
In the workIlow Truncate Target Table Option. I want to insert the deIault record aIter trucating
but beIore loading. Should I put inserting in pre-loading somewhere?
5. How to mark all dulpicates records in a Iile as '1' and all unrepeated rows as '0'
II my Ilat Iile have empnum col
empnum

1
2
2
2
3
4
4

then it should be marked as below
empnum mark

1 0
2 1
2 1
2 1
3 0
4 1
4 1
you can try the Iollowing approach.
SRC--SQ-----------------~JNR--~EXP--~TGT
AGG--~
In aggregator select group by empnum and create one out put port count(empnum)
From aggregator out put looks like below
empnum,count
1,1
2,3
3,1
4,2
Join this data with source data based on empnum
aIter joiner data looks like below
empnum,count
1,1
2,3
2,3
2,3
3,1
4,2
4,2
In expression create out put port mark and use iiI(count1,0,1)
out put Irom expression will be like below
empnum,count,mark
1,1,0
2,3,1
2,3,1
2,3,1
3,1,0
4,2,1
4,2,1
you can achive this with out using aggregator.
But it will be quit complex logic you have to implement.
SRC--~SQ--~SRT--~EXP--~SRT--~EXP--~TGT
One liner unix cmd to get count of running workflows
ps -elI , grep -i pmdtm , grep -v grep , awk ' print $26 " " $35 }' , grep -v '` $' , awk 'BEGIN
FS" "} print substr($1,0,index($0,".")-1) " " split($2, a, "") " " a|1| "" a|2| "" a|3| "" a|4|
"" a|5| "" a|6| }' , cut -I2 -d ":" , sort -u , cut -I1 -d " " , awk 'print , "grep -in " $0 }' , awk
'BEGIN FS":"} print $2 " " $1} ' , sort -t" " -k 1,1 -k2,2r , awk 'a ! $1 a$1; print $0;
next}'
Let me explain what it does. There are three parts but all are piped.
Part a is normal stuII to grep Ior pmdtm: ps -elI , grep -i pmdtm , grep -v grep , awk ' print $26 "
" $35 }' , grep -v '` $' ,
Part b is an awk that Iilters Ior the workIlows only (no sessions): awk 'BEGIN FS" "} print
substr($1,0,index($0,".")-1) " " split($2, a, "") " " a|1| "" a|2| "" a|3| "" a|4| "" a|5| ""
a|6| }' , cut -I2 -d ":" , sort -u , cut -I1 -d " " , awk 'print , "grep -in " $0 }' , awk 'BEGIN
FS":"} print $2 " " $1} ' ,
Part c is a sort Ior unique: sort -t" " -k 1,1 -k2,2r , awk 'a ! $1 a$1; print $0; next}'

One liner unix cmd to get domain name for 8.6
DomainName` ps -elI , grep 'DINFADOMAINSFILE' , grep -v grep , tr -s " " , cut -I20 -d " "
, awk -F'' 'print , "cat " $2}' , grep 'domainName' , awk -F',~'
'/domainName~|`~|\/domainName~/print $3}'`

You might also like