Sie sind auf Seite 1von 7

How to create or implement slowly changing dimension (SCD) Type 2 Flagging mapping in

informatica?

SCD type 2 will store the entire history in the dimension table. Know more about SCDs at Slowly
Changing Dimensions Concepts.

We will see how to implement the SCD Type 2 Flag in informatica. As an example consider the
customer dimension. The source and target table structures are shown below:
--Source Table

Create Table Customers
(
Customer_Id Number Primary Key,
Location Varchar2(30)
);

--Target Dimension Table

Create Table Customers_Dim
(
Cust_Key Number Primary Key,
Customer_Id Number,
Location Varchar2(30),
Flag Number
);

The basic steps involved in creating a SCD Type 2 Flagging mapping are
Identifying the new records and inserting into the dimension table with flag column value as one.
Identifying the changed record and inserting into the dimension table with flag value as one.
Identify the changed record and update the existing record in dimension table with flag value as
zero.

We will divide the steps to implement the SCD type 2 flagging mapping into four parts.

SCD Type 2 Flag implementation - Part 1

Here we will see the basic set up and mapping flow require for SCD type 2 Flagging. The steps
involved are:
Create the source and dimension tables in the database.
Open the mapping designer tool, source analyzer and either create or import the source definition.
Go to the Warehouse designer or Target designer and import the target definition.
Go to the mapping designer tab and create new mapping.
Drag the source into the mapping.
Go to the toolbar, Transformation and then Create.
Select the lookup Transformation, enter a name and click on create. You will get a window as
shown in the below image.



Select the customer dimension table and click on OK.
Edit the lookup transformation, go to the ports tab and remove unnecessary ports. Just keep only
Cust_key, customer_id and location ports in the lookup transformation. Create a new port
(IN_Customer_Id) in the lookup transformation. This new port needs to be connected to the
customer_id port of the source qualifier transformation.



Go to the conditions tab of the lookup transformation and enter the condition as Customer_Id =
IN_Customer_Id
Go to the properties tab of the LKP transformation and enter the below query in Lookup SQL
Override. Alternatively you can generate the SQL query by connecting the database in the Lookup
SQL Override expression editor and then add the WHERE clause.

SELECT Customers_Dim.Cust_Key as Cust_Key,
Customers_Dim.Location as Location,
Customers_Dim.Customer_Id as Customer_Id
FROM Customers_Dim
WHERE Customers_Dim.Flag = 1

Click on Ok in the lookup transformation. Connect the customer_id port of source qualifier
transformation to the In_Customer_Id port of the LKP transformation.
Create an expression transformation with input/output ports as Cust_Key, LKP_Location,
Src_Location and output ports as New_Flag, Changed_Flag. Enter the below expressions for
output ports.

New_Flag = IIF(ISNULL(Cust_Key), 1,0)
Changed_Flag = IIF( NOT ISNULL(Cust_Key) AND
LKP_Location != SRC_Location, 1, 0)

The part of the mapping flow is shown below.



SCD Type 2 Flag implementation - Part 2

In this part, we will identify the new records and insert them into the target with flag value as 1. The
steps involved are:
Now create a filter transformation to identify and insert new record in to the dimension table. Drag
the ports of expression transformation (New_Flag) and source qualifier transformation
(Customer_Id, Location) into the filter transformation.
Go the properties tab of filter transformation and enter the filter condition as New_Flag=1
Now create a update strategy transformation and connect the ports of filter transformation
(Customer_Id, Location). Go to the properties tab and enter the update strategy expression as
DD_INSERT.
Now drag the target definition into the mapping and connect the appropriate ports of update
strategy transformation to the target definition.
Create a sequence generator and an expression transformation. Call this expression
transformation as "Expr_Flag".
Drag and connect the NextVal port of sequence generator to the Expression transformation. In the
expression transformation create a new output port (Flag) and assign value 1 to it.
Now connect the ports of expression transformation (Nextval, Flag) to the Target definition ports
(Cust_Key, Flag). The part of the mapping flow is shown in the below image.



SCD Type 2 Flag implementation - Part 3

In this part, we will identify the changed records and insert them into the target with flag value as 1.
The steps involved are:
Create a filter transformation. Call this filter transformation as FIL_Changed. This is used to find the
changed records. Now drag the ports from expression transformation (changed_flag), source
qualifier transformation (customer_id, location), LKP transformation (Cust_Key) into the filter
transformation.
Go to the filter transformation properties and enter the filter condition as changed_flag =1.
Now create an update strategy transformation and drag the ports of Filter transformation
(customer_id, location) into the update strategy transformation. Go to the properties tab and enter
the update strategy expression as DD_INSERT.
Now drag the target definition into the mapping and connect the appropriate ports of update
strategy transformation to the target definition.
Now connect the Next_Val, Flag ports of expression transformation (Expr_Flag created in part 2) to
the cust_key, Flag ports of the target definition respectively. The part of the mapping diagram is
shown below.



SCD Type 2 Flag implementation - Part 4

In this part, we will update the changed records in the dimension table with flag value as 0.
Create an expression transformation and drag the Cust_Key port of filter transformation
(FIL_Changed created in part 3) into the expression transformation.
Go to the ports tab of expression transformation and create a new output port (Flag). Assign a
value "0" to this Flag port.
Now create an update strategy transformation and drag the ports of the expression transformation
into it. Go to the properties tab and enter the update strategy expression as DD_UPDATE.
Drag the target definition into the mapping and connect the appropriate ports of update strategy to
it. The complete mapping image is shown below.





Scenario :How to delete header and footer in flat file.Possible or different Ways need to be explained
Scenario :In source we have 1000 rows and i have 3 tragets .The 1st 100 rows have to go in 1st
target and the next 200 rows in 2nd traget and the rest of the rows in the 3rd tgt.
Scenario :We have some duplicate rows in the Source table ,We need to separate the duplicate and
Non-Duplicate records.We have 2 targets the unique records has to be loaded in the 1st target and
the duplicate records in 2nd target.
Scenario :We have Empno,Name ,Loc in the source table ,We have two targets the 1st target is Tgt_
1 and Tgt_2. when the employee moves from BNG to HYD the row of that employee must be
inserted in Tgt_2 and must be deleted in Tgt_1 and vice versa.
Scenario :What is Direct and Indirect in flat file property.In What scenario do you opt for them
Scenario :What are the types of Caches
Scenario : I want to update the target table only, without using Dynamic Cache
Scenario : I have used Sql override in lookup ,there are 5 ports from Col A to Col D But I have used
override for first 3 columns Col A, Col B, Col C order by Col B and mapping is validated .when i run
the mapping the session throws error and Sql overide is not valid.
Scenario : I have to join table is it better using the Sql override or lookup or Joiner. Performance
wise which is better and explain it
Scenario :Doing overrides in Source Qualifier can give a better performance or not
Scenario: In workflow I have a reusable Session, the same session is reused across other workflow.
Any change made in either of the Session does reflect in the other Sessions.
Scenario :Can we make any changes in reusable & Non reusable Session ,yes or no
Scenario : In my mapping the Update Strategy is not Updating ,What could be the reason
Scenario : Is it better filtering the rows in filter or in Source Qualifier
Scenario : We have a table with following columna names(c1, c2, c3) and data sampe is as follows
100,x,y and 200,a,b and now we want the target output as follows
c1, c2
100,x
100,y
200,a
200,b How do you desing a mapping
Scenario : What approach do you follow for loading more than 1 flat files which are having same
structure to a single target
Scenario : Write a Query to diplay those deptno where the count of the employees is more than 10
people.There are 3 depts in dept table and one with 100 people and 2nd with 5 and 3rd with some
30 and so.Similarly Design a informatica mapping.

Das könnte Ihnen auch gefallen