Monday, 29 September 2014

Slowly Changing Dimension 2(SCD2) -Version Control

What is a Slowly Changing Dimension?
  1. Although dimension tables are typically static lists, most dimension tables do change over time.
  2. Since these changes are smaller in magnitude compared to changes in fact tables, these dimensions are known as slowly growing or slowly changing dimensions.
  3. Slowly changing dimensions are classified into three different types
    1. TYPE I
    2. TYPE II
      1. TYPE 11 -Version Control
      2. TYPE 11- Flag Control
      3. TYPE 11 - Date Control
    3. TYPE III
Slowly Changing Dimension 2(SCD2) - Version Control


Process :

Step 1: Create Source Table & Data
  1. We can use Scott Schema EMP table

  1. Import table using source analyzer

Step 2: Create Target Table

  1. Create target table in target database
 
CREATE TABLE EMP_SCD2_VERSION
  ( EMPKEY NUMBER(5,0) PRIMARY KEY,
EMPNO NUMBER(5,0),
ENAME VARCHAR2(20 BYTE),
JOB VARCHAR2(20 BYTE),
SAL NUMBER(10,2),
DEPTNO NUMBER(5,0),
VERSION NUMBER(5)
  )

  1. Import table using Target Designer






Step 3: Create mapping with transformations

  1. Create a mapping with the name m_SCD2_VERSION
  2. Drag and drop source and target into work area
  1. Introduce  Lookup transformation and select lookup table as EMP_SCD2_VERSION
  2. Drag and drop EMPNO from Source Qualifier to Lookup and rename it as EMPNO_in
  3. Click on condition tab of lookup provide join condition as shown below
  1. Click on properties tab and select multiple match property as last value
  1. Introduce Expression transformation into work area and name it as exp_INSERT_UPDATE_NOCHANGE
  2. Drag and drop ports EMPNO,ENAME,JOB,SAL,DEPTNO from source qualifier to expression
  3. Drag and drop ports EMPKEY,JOB,SAL,VERSION from Lookup to expression and rename job,sal,version as job_previous ,sal_previous,version_previous respectively
  4. Add one new port in expression and name it as INSERT_UPDATE_NOCHANGE_FLAG
  5. Develop expression using below formula

IIF(
ISNULL(EMPKEY),'I',
IIF(
(JOB != JOB_previous) OR
      (SAL != SAL_previous),'U','NC' ) )

  1. Introduce ROUTER transformation → Drag and drop EMPNO,ENAME,JOB,SAl,DEPTNO,INSERT_UPDATE_NOCHANGE_FLAG  and VERSION_previous from expression to router
  1. Double click on ROUTER header → click on groups tab → add a group as shown

  1. Introduce Expression transformation→ from INSERT section of router drag and drop ports EMPNO1,ENAME1,JOB1,SAL1,DEPTNO1,VERSION_previous1 and INSERT_UPDATE_NOCHANGE_FLAG1
  2. Create two new ports EMPKEY ,VERSION
  3. Introduce Sequence generator transformation and connect NEXTVAL with EMPKEY
  4. develop below expression in version port
  1. Overall it looks like below
  1. Introduce update strategy transformation and connect as shown
  1. Connect ports from update strategy transformation to target as shown
  1. save it



Step 4: Create Workflow and Session
  1. Create workflow and session as shown below
  1. Double click on session task provide source and target connection accordingly
  1. Save the workflow
Step 5: Run workflow and Observe output
  1. Observe source data in my case
  1. Select Start task → click on run
  2. observe target data
  1. Observe target table output
  1. Update any one existing record in my case iam updating RAM REDDY sal from 8000 to 10000
  1. Run Workflow again

Step 6: Download workflow XML Code and observe it


No comments:

Post a Comment