Você está na página 1de 15

Lab

SCD TYPE2

Lab at a Glance ..............................................................2


Objectives........................................................................2
Summary .........................................................................2
Duration...........................................................................2
Exercises........................................................................3
Exercise 1: Import Sources and Targets ...........................3
Exercise 2: Create the Mapping .......................................5
Exercise 3: Create and Run the Workflow....................... 15

PowerCenter 9.x Level I Developer Lab Guide 11 - 1


Lab. SCD TYPE2

Lab at a Glance
The exercises in this lab are designed to walk the student
through the process of using a Lookup transformation and an
Update Strategy transformation to do an SCD type1
implementation.

Objectives
After completing the lab, the student will be able to:
Understand the how to load SCD type 2

Summary
The purpose of this lab is to pull information from the
SCD_INPUT flat file. The DIM_SUPPLIER2 table will be
updated to keep only the current and Historical suppliers
information.
The completed mapping should look as follows:

Duration
This lab should take approximately 40 minutes.

11 - 2 PowerCenter 9.x Level I Developer Lab Guide


Lab. SCD TYPE2

Exercises

Exercise 1: Import Sources and Targets


Step 1. Import flat file.

Continue to work in the assigned student folder


In the Designer, open the Source A nalyzer by clicking the
Source Analyzer button or by selecting Tools | Source
A nalyzer.

Select Sources | Import From File.

Import the SCD_INPUT flat file from source folder.


The source definition look as follows:

PowerCenter 9.x Level I Developer Lab Guide 11 - 3


Lab. SCD TYPE2

Step 2. Import the target table.

Clear the Warehouse Designer workspace by right-


clicking anywhere in the work area and selecting Clear A ll.
Import the DIM_SUPPLIER2 relational target from the
TDBUxx database schema.

11 - 4 PowerCenter 9.x Level I Developer Lab Guide


Lab. SCD TYPE2

Exercise 2: Create the Mapping


Step 1. Create a mapping.

Create a mapping and name it m_SCD_TYPE2.


Add the SCD_INPUT source definition.
Add the DIM_SUPPLIER2 target definition twice one for
INSERT and Other for Update.
Save the repository.
Step 2. Create a Lookup transformation (connected).

PowerCenter 9.x Level I Developer Lab Guide 11 - 5


Lab. SCD TYPE2

Add a Lookup transformation to the mapping.


The Select Lookup Table for Lookup Transformation dialog
box appears.
Click the Target button and select the DIM_SUPPLIER2
table to be the lookup table.

Click OK.
Copy/link SUPPLIER_CODE from SQ_SCD_INPUT to the
Lookup transformation.
Rename the Lookup transformation
lkp_DIM_SUPPLIER2.
Rename the port SUPPLIER_CODE, which came from
sq_SCD_INPUT, to SUPPLIER_CODE_in.

Add the following lookup condition:


SIPPLIER_CODE = SIPPLIER_CODE_in
Click the OK button and save the repository.

11 - 6 PowerCenter 9.x Level I Developer Lab Guide


Lab. SCD TYPE2

Step 3. Create an Expression transformation.

Create a new Expression transformation.


Select all ports within the SQ_SCD_INPUT source
qualifier, then drag-and-drop them onto the Expression
transformation.And suffix _SRC to copied ports.
And pull the supplier_key,supplier_cd, supplier_name
and suppler_state to the expression. And rename
SUPPLIER_KEY to SUPPLIER_KEY_LKP,
SUPPLIER_CD to SUPPLIER_CD_LKP,
SUPPLIE_NAME to SUPPLIE_NAME_LKP and
SUPPLIER_STATE to SUPPLER_STATE_LKP
Double-click on the header of the Expression
transformation.
The Edit Transformations dialog appears.
Click the Rename button.
Enter exp_DIM_SUPPLIER2 in the Transformation Name
field and click the OK button.
Click on the Ports tab.

Add the following ports by clicking the A dd Port


button:
V_SRC_MD5, Datatype=string,
Prec=1000(default), Port
Type=Variable Only

V_LKP_MD5, Datatype=string,
Prec=1000(default), Port
Type=Variable Only

CHG_FLAG, Datatype=string,
Prec=1(default), Port Type=Output
Only
CHG_FLAG, Datatype=string,
Prec=1(default), Port Type=Output
Only
INS_FLAG, Datatype=string,
Prec=1(default), Port Type=Output
Only

CURR_DATE, Datatype=DATE, Prec=29,9,


Port Type=Output Only
MAX_DATE , Datatype=DATE, Prec=29,9,

PowerCenter 9.x Level I Developer Lab Guide 11 - 7


Lab. SCD TYPE2

Port Type=Output Only

PREV_DATE, Datatype=DATE, Prec=29,9,


Port Type=Output Only

An expression will be needed for each of the above ports


to derive the values. Open the Expression Editor and add
expressions for each port as follows:

V_SRC_MD5=MD5(Supplier_Name_SRC||Supplier_State_SRC)

V_LKP_MD5=MD5(SUPPLIER_NAME_LKP||SUPPLIER_STATE_L
KP)

INS_FLAG= IIF(ISNULL(SUPPLIER_CODE_LKP),'Y','N')

CHG_FLAG= IIF(NOT ISNULL(SUPPLIER_CODE_LKP) AND


V_SRC_MD5<>V_LKP_MD5,'Y','N')

out_CURR_DATE=SYSDATE

out_MAX_DATE= TO_DATE('31-DEC-2999','DD-MON-YYYY')

out_PREV_DATE= ADD_TO_DATE(SYSDATE,'DD',-1)

Change the ports, SUPPLIER_CODE_LKP ,


SUPPLIER_NA ME_LKP and SUPPLIER_STA TE_LKP, to input
only ports.
The Ports tab of the exp_SUPPLIERS_TYPE2 expression
should look as follows:

11 - 8 PowerCenter 9.x Level I Developer Lab Guide


Lab. SCD TYPE2

Click the OK button.


Step 2. Create a router transformation.

Create a Router transformation and name it


rtr_SUPPLIERS_TYPE2.
Copy/Link all of the ports from exp_SUPPLIERS_TYPE2 to
rtr_SUPPLIERS_TYPE2.
Edit the rtr_ODS_EMPLOYEE_TYPE transformation and
select the Groups tab.
Click on the A dd a new group button:

Rename NEWGROUP to INSERT. Ignore the Default group;


it will not be used.
Add the following Group Filter Condition :
The Router tests each row against ev ery
group condition, so a row can ex it the
INS_FLAG='Y' OR CHG_FLAG='Y'
transformation multiple times.
Add one more group named UPDATE.
When the row does not CHG_FLAG='Y'
meet any condition, it
is placed in the Default
Group. The row can exit
the default group if the
por
ts are linked to another trans formation, or
simply terminate there.

If it is not the last group, select the DEFA ULT group and
move it to the bottom. Order does not matter to row
evaluation, but is helpful for clarity.
Click OK.
Step 4. Create Sequence Generator transformation.

Create an Sequence transformation and name it seq_SUPPLIER_PK

PowerCenter 9.x Level I Developer Lab Guide 11 - 9


Lab. SCD TYPE2

11 - 10 PowerCenter 9.x Level I Developer Lab Guide


Lab. SCD TYPE2

Step 4. Create an update strategy transformation.

PowerCenter 9.x Level I Developer Lab Guide 11 - 11


Lab. SCD TYPE2

Create an Update Strategy transformation and name it


upd_DIM_SUPPLIER2_INS.
Copy/Link Supplier_Code_SRC1, Supplier_Name_SRC1
, supplier_State_SRC1,MAX_DATE AND
CURR_DATE from INSERT group to
upd_DIM_SUPPLIER1_INS.

Click on the Properties tab. Add the following


expression:
DD_INSERT
On the Properties tab, uncheck the Forward Rejected Rows
checkbox:key
Add the new port SUPPLIER_KEY and Copy/Link this
from NEXTVAL of SEQ_SUPPLIER_KEY
Tranformation.

With the Forward Rejected Rows


selected, the Informatica Serv er forw ards
the row s to the nex t transformation, then
flags the row s for reject and ultimately
w rites them to the session reject file.
When not selected, the Informatica Serv er
drops rejected row s and w rites them to the
session log file.

This keeps rejected rows from being forwarded through


the mapping. They drop instead to the session log file.
Step 4. Create an update strategy transformation.

Create an Update Strategy transformation and name it


upd_DIM_SUPPLIER2_UPD.
Copy/Link supplier_key_lkp3,PREV_DATE AND
CURR_DATE from UPDATE group to
SUPLLIERS_SCD_TYPE_UPD.
Click on the Properties tab. Add the following
expression:
DD_UPDATE

11 - 12 PowerCenter 9.x Level I Developer Lab Guide


Lab. SCD TYPE2

step 5. Link target definition from


SUPLLIERS_SCD_TYPE_UPD and
SUPLLIERS_SCD_TYPE_INS.

PowerCenter 9.x Level I Developer Lab Guide 11 - 13


Lab. SCD TYPE2

Save the repository.

11 - 14 PowerCenter 9.x Level I Developer Lab Guide


Lab. SCD TYPE2

Exercise 3: Create and Run the Workflow

PowerCenter 9.x Level I Developer Lab Guide 11 - 15

Você também pode gostar