Informatica Mapping Scenarios
Informatica Mapping Scenarios
Informatica Mapping Scenarios
30 D
40 E
T2
col1 col2
10 A
20 C
Solution:
Source Qualifier; Expression Transformation,Sorter Transformation ,Router Transformation
1)Link ports from Source qualifier to sorter transform for key col1, col2
sorted data:
10 A
10 A
20 C
20 C
30 D
40 E
2)Link ports to Expression Transform:
New ports :
v_count =decode(COL1,v_pre_col1 ,decode(COL2,v_pre_col2,v_count+1,1),1)
o_count=v_count
v_pre_col1=COL1
v_pre_col2=COL2
3)Link to Router Transform:
Group:
4) link all Output ports to target
Scenario 5:
Unpivorting the records
Source:
col1 qt1 qt2 qt3 qt4
1
2
3
Target:
100
100
100
200
200
200
300
300
300
400
400
400
OUT_EXP=DECODE(GCID_exp,1,'QT1',2,'QT2',3,'QT3','QT4')
3) Link ports Col1, exp and OUT_exp to Target.
Scenario 6 : Get the highest salaried and lowest Salaried employee for each department.?
Union Transformation,Rank Transformation
1) Drag 2 rank Transform :
RNKTRANS : Get Highest salary
Set Properties : Number of Ranks =1 , Top/Bottom = Top
RNKTRANS1: Get Lowest salary
Set Properties : Number of Ranks =1 , Top/Bottom = Bottom
2)Drag Union Transform :
a) Link all ports to Default Group
b) Create two groups : TOP_SAL and BOTTOM_SAL:
3) Link all Ports to target.
Suppose we have customer data coming in below format and we want to have last 3 rows in
target
Step1)
Create expression transformation (exp_Build_Logic) drag all three input ports and create three
extra ports as below
v_dummy (Output Port) Assign Value 1 to it
v_Total_Count (Variable Port) := v_Total_Count+1
o_Total_Count := v_Total_Count
Step2) Create Aggregator transformation with all ports and do not choose any port as group by
port
Step 3)
Create Joiner transformation jnr_Agg_Expression as Sorted Input (You need to choose this
option as you are trying to use two sources originating from same source)
Take two ports from aggregator and rest from expression transformation and join on field
v_dummy
Mapping
Output required is
A
B
C
I have seen rarely a candidate answer this question correctly. Their answer is mostly
a crammed (by reading on various website) without understanding core concept of
informatica transformations.
I will explain three methods to achieve this then we will find out which one is best
method
1.
2.
3.
Router Transformation
Normalizer Transformation
Java Transformation
Router Transformation : This method take advantage of the fact that router is an
active transformation and one row can fall into multiple groups i.e. if a row satisfies
condition of three groups then it will fall into three groups and will produce three
rows for one input row.
Step1)
Suppose we have a source with three input columns
Step3) Create a router transformation with three output groups with condition
GROUP1 : substr(FLD_OUTPUT,1,instr(FLD_OUTPUT,'#')-1)=FLD1
GROUP2 : substr(FLD_OUTPUT,instr(FLD_OUTPUT,'#')+1,instr(FLD_OUTPUT,'#',2)1)=FLD2
GROUP3: substr(FLD_OUTPUT,instr(FLD_OUTPUT,'#',3)+1)=FLD3
Purpose of this is that row will fall into three groups ..we are extracting string from
concatenated string are comparing to respective field.i.e value A will be in first
group and B in second group and so on
Step4) Create union transformation to combine output from three output group from
router..Take FLD1 from first group, FLD2 from second group ,FLD3 from third group
Core Concept: if a row satisfies condition of three groups then it will fall into three
groups and will produce three rows for one input row.
You can define number of occurrence of source field, Once you define number of
occurrence then informatica automatically creates that number of input ports. In
this case 3
Connect FLD1, FLD2 and FLD3 from source or expression in step2 of first method
and FLD as output connected to target.
Generate Transaction
Create a java transformation with one input and one output field
Now connect concatenated field (A#B#C) from expression in step2 of first method
to FLD_INPUT of java transformation
String[] str_fld_nm=FLD_INPUT.split("#");
for(int i=0; i
FLD_OUTPUT =str_fld_nm[i];
generateRow();
}
It is using java functionality of array to break input field and multiple fld and then
taking advantage of generateRow() to produce multiple rows.
A
B
C
Core concept : Java functionality to break concatenated string into multiple fields
and generateRow() to produce multiple rows.
Now we have covered all three features. Let us see which one is best
Feature
Router
Normaliser
Java
Flexiblity
Ease
High as developer
are comfortable
with using router
transformation
Medium as
developer dont use
it frequently
Low. As most
developer are not
from java
background. It is
difficult for them to
understand it
1. Invoice_ID
2. Invoice_No
3. Invoice_Amount
4. Vendor_Id
We need to separate all details related to one vendor in separate file so that we can pass data
to third part vendors in separate file.
INVOICE_DETAILS
INVOICE
_ID
INVOICE_
NO
INVOICE_AMO
UNT
VENDOR
_ID
1 A01
100.00
10
2 A02
125.00
10
3 A03
150.00
10
4 B01
200.00
20
5 B02
500.00
20
6 D01
345.00
40
7 C01
230.00
30
8 D02
450.00
40
9 E01
40.00
50
Step1 ) Import INVOICE_DETAILS and drag into mapping and connect all port from Source
qualifier to expression and do below sql override
Step2) Create expression transformation with as below with 4 input port plus
1.
2.
3.
CHECK_VENDOR_IDOUTPUT_VENDOR_ID (Output)
Step 4 ) Create a File Target with same structure as source table and new field in target using
option Add FileName to this Table
Interviewer asked How will you get first 3 records from flat file source? ...You will
say in your mind thats simple
You reply We can use variable in expression and increment it and the use filter
transformation to pass just first two records
Interviewer will come up with a new trick in his sleeve How will you get last 3
records from flat file source?
Dj vu J
You will think and try to build some logic on the fly and try to explain may we can
use this transformation or some another transformation and will get bit confused.
Suppose we have customer data coming in below format and we want to have last 3
rows in target
Step1)
Create expression transformation (exp_Build_Logic) drag all three input ports and
create three extra ports as below
Step2) Create Aggregator transformation with all ports and do not choose any port
as group by port
Step 3)
Take two ports from aggregator and rest from expression transformation and join on
field v_dummy
Step5)
Output will be
Mapping
Informatica Common Errors :The Target Definition has more than one
Transaction Control point connected to it
Error : The Target Definition has more than one Transaction Control point
connected to it
Scenario :
Create a mapping with two streams( one with Transaction control and Second
without Transaction control)..You will get above error
Reason :
Solution :
Recently i started with informatica in dual monitor and found few issues (Like
Expression editor size and sq editor getting greyed out)
Solution
At commend prompt type regedit and go to below path (Please take backup of
registry before making any changes)
HKEY_CURRENT_USER\Software\Informatica\PowerMart Client
Tools\9.1.0\Designer\Options\Global\Editor\SQL
There is a source table containing 2 columns Col1 and Col2 with data as
follows:
Col1
a
b
a
a
b
x
Col2
l
p
m
n
q
y
Design a mapping to load a target table with following values from the
above mentioned source:
Col1
a
b
x
Col2
l,m,n
p,q
y
Solution:
Use a sorter transformation after the source qualifier to sort the values with col1 as
key. Build an expression transformation with following ports(order of ports should
also be the same):
1. Col1_prev : It will be a variable type port. Expression should contain a variable e.g
val
2. Col1 : It will be Input/Output port from Sorter transformation
3. Col2 : It will be input port from sorter transformation
4. val : It will be a variable type port. Expression should contain Col1
5. Concatenated_value: It will be a variable type port. Expression should be
decode(Col1,Col1_prev,Concatenated_value||','||Col2,Col1)
6. Concatenated_Final : It will be an outpur port conating the value of
Concatenated_value
After expression, build a Aggregator Transformation. Bring ports Col1 and
Concatenated_Final into aggregator. Group by Col1. Don't give any expression. This
effectively will return the last row from each group.
Connect the ports Col1 and Concatenated_Final from aggregator to the target table.
Scenario 4:
Normalizer Transformation
Normalizer transformation is an Active and Connected transformation.
For example, you might have a relational table that stores four quarters of sales by
store. You need to create a row for each sales occurrence. You can configure a
Normalizer transformation to return a separate row for each quarter.
Source Data:
EmpId
Ename
Salary1
Salary2
Salary3
1001
Raju
5000
8000
10000
1002
Ravi
6000
7000
11000
1003
Anil
4000
3000
5000
EmpId
Ename
Salary
1001
Raju
5000
1001
Raju
8000
1001
Raju
10000
1002
Ravi
6000
1002
Ravi
7000
1002
Ravi
11000
1003
Anil
4000
1003
Anil
3000
1003
Anil
5000
Target Data:
Sample mapping:
1. Connect and Open the folder if not already opened.
2. Select Tools --> Mapping Designer
4. Drag the Source and Target definitions into workspace if they are already exist. If
not click here to know how to create or import Table definitions.
b) Select 'Normalizer' from drop down and 'Enter a new name for this
transformation:' as "nrm_salaries"
OR
d) In Transformation tab --> Click on 'Rename' highlighted above which will pop-up
'Rename Transformation'. Enter the Transformation Name: "nrm_salaries"
e) Click on 'OK'
f) Click on 'Apply' and 'OK'.
Note: We cannot drag any port into Normalizer transformation. We have to create
port and defined datatypes, length.
6). Select 'nrm_salaries' Normalizer transformation in workspace and Right Click -->
Edit.
a) Go to 'Normalizer' tab, to create ports
b) Now, defined the 'SALARY' occurrence as 3. Which tells Informatica who many
sequence columns need to loop for the other columns.
c) Now, go to the tab Port and see, we got 3 ports for salary.
Reset: At the end of a session, resets the value sequence for each generated key
value to the value it was before the session
Restart: Starts the generated key sequence at 1. Each time you run a session, the
key sequence value starts at 1 and overrides the sequence value on the Ports tab.
e) Click 'Apply' and Click 'OK.
INFORMATICA SCENARIOS
Convert single row from source to three rows in target
Scenario1:
We have a source table containing 3 columns : Col1, Col2 and Col3. There is only 1 row
in the table as follows:
Col1
Col2
Col3
There is target table containg only 1 column Col. Design a mapping so that the target
table contains 3 rows as follows:
Col
a
b
c
Without using normaliser transformation.
Solution:
Split the non-key columns to separate tables with key column in both
Scenario 2:
Split the non-key columns to separate tables with key column in both / How to split the
data of source table column-wise with respect to primary key. See the source and target
tables below.
source table: ID is the key column, Name and Phone No are non-key columns
ID
Name
Phone No
10
AAA
123
20
BBB
234
30
CCC
434
40
DDD
343
50
EEE
442
Target Table 1
ID
Name
10
AAA
20
BBB
30
CCC
40
DDD
50
EEE
Target Table 2
ID
Phone No
10
123
20
234
30
434
40
343
50
442
Solution:
Step 1: Source qualifier: get the source table to the mapping area. See image below.
Step 2: Drag all the port from (from the previous step) to the Aggregator transformation and group
by the key column. Since we have to split the columns to two different tables with the key column in
each, so we are going use two expression transformation, each will take the key column and one nonkey column. Connect aggregator transformation with each of the expression transformation as
follows.
Step 3: We need another set of aggregator to be associated with each of the expression
tranformation from the previous step.
Step 4: In the final step connect the aggregators with the two target tables as follows.
COL1
COL2
COL3
COL2
COL3
COL1
COL2
COL3
Solution:
Step 1: Drag the source to mapping and connect it to an aggregator transformation.
Step 2: In aggregator transformation, group by the key column and add a new port call it count_rec
to count the key column.
Step 3: connect a router to the aggregator from the previous step.In router make two groups one
named
"original"
and
another
as
"duplicate"
In original write count_rec=1 and in duplicate write count_rec>1.
The picture below depicting group name and the filter conditions
Scenario 4:
How to get first and last record from a table/file?
Solution:
Step 1: Drag and drop ports from source qualifier to two rank transformations.
Step 2: Create a reusable sequence generator having start value 1 and connect the next
value to both rank transformations.
In Rank2
Drag
and
drop
the
source
to
mapping.
Step:3 Then connect to target, and run mapping to see the results.
Step 3: In expression transformation make two port, one is "odd" and another "even".
And Write the expression like below
EXPRESSION PROPERTY
RTR PROPERTY
col2
col3
Col1
Col2
Col3
Target Table
Solution:
Step 1: Bring the source to
mapping.
RANK PROPERTY
2.
Arrange the salary in descending order in sorter as follows and send the record to
expression.
SORTER PROPERTIES
3.
Add the next value of sequence generator to expression.(start the value from 1 in
sequence generator).
4.
Connect the expression transformation to a filter or router. In the property set the
condition as follows-
5.
Scenario: You have two columns in source table T1, in which the col2 may contain
duplicate values.All the duplicate values in col2 of
separated in the column col2 of target table T2.
Source Table: T1
Col1
Col2
b
col1
n
col2
x,m
y,n
Target Table: T2
col1
col2
Solution:
1.
We
have
to
use
the
following
transformation
as
below.
First connect a sorter transformation to source and make col1 as key and its order is
ascending.
After
that
connect
it
to
an
expression
transformation.
2.
In Expression make four new port and give them name as in picture below.
3.
4.
In
aggregator
group
5.
it
by
col1
and
send
it
to
target
Target table rows , with each row as sum of all previous rows from
source table.
Scenario: How to produce rows in target table with every row as sum of all previous
rows in source table ? See the source and target table to understand the scenario.
SOURCE TABLE
id
Sal
200
300
500
560
TARGET TABLE
Id
Sal
200
500
1000
1560
1.
Pull
the
source
to
mapping
and
then
connect
it
to
expression.
2.
In expression add one column and make it output(sal1) and sal port as input only.
We will make use of a function named cume() to solve our problem, rather using
any complex mapping. Write the expression in sal1 as cume(sal) and send the
output
rows
to
target.
Solution:
1.
Drag your target file to target designer and add a column as show on the picture.
Its not a normal column .click on the add file name to the table property. (I have
given
2.
red
mark
there)
3.
In expression transformation add a new port as string data type and make it
output
4.
port.
In that output port write the condition like describe as bellow and then map it in
to filename port of target. Also send other ports to target. Finally run the session.
You will find two file one with sys date and other one is .out file which one you can
delete.
5.
In repository go to menu tool then queries. Query Browser dialog box will
appear.Then
click
on
new
button.
2.
In Query Editor, choose folder name and object type as I have shown in the
picture.
3.
4.
Query results window will appear. You select single mapping (by selecting single
one) or whole mapping (by pressing Ctrl + A) and go to "tools" then "validate"
option
to
validate
it.
integer
2.
and
give
initial
value
as
20.
particular
department
id
will
be
filtered
to
the
target).
3.
In filter set deptno=$$v1 (that means only dept no 20 record will go to the
target.)
4.
Mapping parameter value cant change throughout the session but variable can
be changed. We can change variable value by using text file. Ill show it in next
scenario.
In the last blog , we learnt about the Aggregator transformation in Informatica , steps to
create it , configuring the port and properties. We also discussed the business scenario of
Aggregator Transformation in Informatica. Now this is the time to apply Aggregator
Transformation in a sample Informatica mapping. Its a very simple but detailed example of
Aggregator Transformation.
Problem Statement :
Create a mapping to populate min , miaximum salary , average and sum of salary for each
department based on the employee data with the help of Aggregator Transformation.
Source Data:
EMP Table Data:
EMPNO
ENAME
JOB
MGR
SAL
COMM
DEPT
1JOHNSON
ADMIN
18000
2HARDING
MANAGE
R
52000
300
3TAFT
SALES I
25000
500
4HOOVER
SALES I
27000
5LINCOLN
TECH
22500
6GARFIELD
MANAGE
R
54000
7POLK
TECH
25000
8GRANT
ENGINEE
R
10
32000
9JACKSON
CEO
75000
3
1400
10FILLMORE
MANAGE
R
56000
11ADAMS
ENGINEE
R
10
34000
18000
10
30000
WASHINGTO
12N
ADMIN
13MONROE
ENGINEE
R
14ROOSEVELT CPA
35000
Target Data:
EMP_RES Data:
EMPNO
ENAME
DEPT
13MONROE
30000
56000
38000
152000
4HOOVER
25000
52000 34666.67
104000
12WASHINGTON
18000
75000 35416.67
212500
14ROOSEVELT
35000
35000
35000
35000
Solution:
Below are the steps to create full mapping.
Drag input port from EMPNO,ENAME, SAL, DEPTNO from SQ_EMP (Source
Qualifier ) to aggr_emp_Salary
Also add additional below output port (by Clicking on Create port button)
o
COUNT
MIN_SAL
MAX_SAL
AVG_SAL
SUM_SAL
Edit the expression for AVG_SAL ( by clicking on expression editor ) and add
below expression
AVG(SAL)
COUNT
= COUNT(SAL)
MIN_SAL = MIN(SAL)
MAX_SAL = COUNT(SAL)
SUM_SAL = SUM(SAL)
In case Sorted Input data is coming to Aggregator, check the Sorted Input
option under the properties Tab.
Note: Some extra additional fields like EMPNO , ENAME, (which are not port of aggregation
transformation functionally ) are added just to show that during the execution , final output data
will contain only the last record per group . Such data is not required allthough.
Click on Mapping ( from tool bar) -> then Validate ( to validate the mapping)
Now save the mapping ( by clicking on Repository-> Save or you can also
press Ctrl+S)