Steps:
Create a new mapping M_US. Drag the source (EMP), target (DIM_JOIN) to the mapping designer workspace. The target table should have a Primary Key.
Create a Lookup Transformation T_LKP_DYN on the target table DIM_JOIN.
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
Project the source ports on the Lookup Transformation.
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
Note: Source ports (EMPNO1,ENAME1, etc. ) are created in the Lookup transformation. Edit the Lookup transformation, Go to Properties Tab.
Check the property Dynamic Lookup Cache
Note that after this property is checked following options get highlighted:
Γ Output Old value On Update
Γ Insert Else Update
Γ Update Else Insert
Before checking Dynamic Lookup Cache property
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
After checking Dynamic Lookup Cache property
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
Select the Property Insert Else Update
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
Now go to Condition Tab and add a condition EMPNO = EMPNO1
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
Go to the Ports tab.
A new port called NewLookupRow is inserted in to the set of ports.
Lookup uses NewLookupRow to identify changes in the Cache
0 No change
1 INSERT
2 UPDATE
It decides what type of data it is – 1 means Inserted data, 2 means updated data.
The condition EMPNO=EMPNO1 is disabled here (it has already been applied in the condition tab).
We apply additional conditions here.
ENAME=ENAME1
JOB=JOB1
MGR=MGR1
HIREDATE=HIREDATE1
SAL=SAL1
COMM=COMM1
DEPTNO=DEPTNO1
DNAME = ENAME1 (not logical, but we still give this condition because otherwise if we don’t assign a value here, it will throw an error and in cache it will be NULL. Since DNAME is not in the source it will just pass ENAME)
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
Go to the Transformation Menu and create an Update Strategy transformation. T_UPS
Project the output ports from Lookup Transformation to Update Strategy.
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
Edit the Update Strategy transformation. Go to Properties tab
In the Formula bar give the following condition:
IIF(NewLookupRow=1,DD_INSERT,IIF(NewLookupRow=2,DD_UPDATE,DD_REJECT)) is equivalent to
IF (NewLookupRow=1)
THEN
DD_INSERT
ELSIF NewLookupRow=2
THEN
DD_UPDATE
ELSE
DD_REJECT
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
An automatic projection happens from lookup transformation to the update strategy port NewLookupRow.
At runtime it decides whether to INSERT or UPDATE.
By default, Session Property is INSERT.
Project the update strategy ports to the target.
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
Save the repository and validate the mapping.
Create a workflow WKF_LKP_DYN_UPS
Assign the Source and Target connections.
Note: In the Target connection give Load Type as Normal (as the TGT is having primary key) and do not select truncate the target table option because here we want to see the changes.
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
Assign the connection for the Lookup Connection (MEEN_TGT because lookup table is DIM_JOIN which is in the target database).
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
Select the Dynamic Lookup Cache option and Insert Else Update option.
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
In the Session properties set the attribute Treat source rows as to Data Driven.
Save the repository. Validate and start the workflow .
Preview the output of the target table.
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
Normal output
Now let us observe the newlookuprow attribute.
INSERT a new record in the Source table EMP.
SQL> INSERT INTO EMP(EMPNO,ENAME,SAL,DEPTNO)
2 VALUES (9000,'MEENAKSHI',3000,10);
1 row created.
SQL> COMMIT;
Preview the output again
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
The new record has been INSERTED.
Now let’s Update
SQL> update emp
2 set sal=3500
3 where empno=7499;
1 row updated.
SQL> commit;
Preview the output
DYNAMIC LOOKUP WITH UPDATE STRATEGY |
Comments
Post a Comment