Beruflich Dokumente
Kultur Dokumente
Velocity
Visio Templates for Slowly Changing
Dimension Type 2 Mappings
Document Author:
Document Owner:
Date Created:
Last Updated:
Project:
Company:
Introduction
Data warehouses store historical data in various forms. One of the most common components
is a set of Slowly Changing Dimension (SCD) tables. These contain historical information of
objects to allow analysis of past situations. PowerCenter mappings that load these tables often
follow a common structure; hence they lend themselves for generation using a Mapping
Architect for Visio template. This document describes two different SCD Type 2 designs and
provides corresponding template files for each while keeping maximum reusability of
PowerCenter logic in mind. The templates can be used as examples or as a basis to customize
to specific needs. The variety of techniques used allow for several variations of mappings to be
generated using a single template.
We start with a short description of the basic SCD Type 2 process that needs to be generated,
followed by the first template and an explanation of various rules. We continue with additional
functionality, including the (more complex) template. Refer to the Mapping Architect for Visio
Guide for more information about specific options.
The example in this sample deliverable uses the following technical columns:
Column Name Datatype Description S H
2|
The overall process flow looks like this:
Calculate
Source S-table
key and
Data
checksum
Perform
Comparison
Apply Changes
H-table
The source data is loaded into the S-table. In this step the UNQ_ID_SRC_STM and
HASH_VALUE columns are calculated and stored in the table. The MD5 checksums of the
records in the S-table and the last known version of each object in the H-table are then
compared. This is done using a full outer join on the UNQ_ID_SRC_STM column and an
expression transformation. The CHANGE_IND column is calculated and can have the following
values:
Value Description
I New record detected in source data (key does not yet exist in H-table)
U Updated record detected in source data (checksum differs from last known
version)
D Record no longer occurs in source data (key no longer exists in S-table)
R Previously deleted record reappeared in source data
X No change detected
The physical inserts and updates that are performed in the target table depend on the type of
change that is detected:
Value H-table
X No action
The layout of the mapping is independent of the structure of the data that is being processed.
The transformations are always identical while only the table/column names and data types will
differ. This makes it an ideal candidate for mapping generation using Mapping Architect for
Visio. Also, most of the transformations are identical for every mapping so that they can be
defined as reusable transformations to simplify future maintenance. It is even possible to use
shortcuts to reusable transformations. However, for simplicity, this has not been done in the
example.
4|
Mapping Template
Visio Template
The Mapping Architect for Visio template to generate mappings looks like this:
As can be seen above, the structure is identical to the PowerCenter mapping. Only the
components that are different in each mapping are parameterized in the template.
Rule Types
The links between the transformations contain rules that can have different types. This example
template uses the types described below.
Type Description Where Used (examples)
1. Named Propagate a port using fixed from and to port names. Everywhere
2. Pattern Propagate ports using regular expressions to select Between source qualifiers
from port names and calculate to port names. In this and joiner, between router
example these rules are used to add/remove and target definitions.
prefixes and suffixes.
Template Parameters
The template uses a single parameter to generate the PowerCenter mappings.
Name Description Where Used
1. $TABLE_CODE$ Identification of the source/target Source/target definitions,
definitions to be used in the mapping. This Source Qualifiers,
is the part between ‘TB_’ and ‘_S/_H’ in Sequence generator
the table names.
The values of template parameter(s) need to be provided when a mapping is generated. This
can be done in the PowerCenter Designer using the Import Mapping Template wizard or using
parameter files. The latter are XML-files that can be generated (using for instance PowerCenter)
Example Files
The following files can be used to generate the example mapping. To be complete, the mapping
itself is also included for reference.
File Description
1. Source/Target definitions to be used for mapping generation
Tabledefs.XML
H_DT_Basic.vsd
H_DT_Basic.xml
H_DT_Basic_param_
DATASET.xml
5. Example PowerCenter mapping
TB_DATASET_H_DT_
Basic.XML
6|
Calculate
Source S-table
key and
Data
checksum
Perform
Comparison
Apply Changes
DT-table H-table
Physically, records will only be inserted into the new DT target table. However, the content of
the records depends on the type of change (indicated by the CHANGE_IND value):
Value DT-table
The overall layout of the mapping is still independent from the structure of the data that is being
processed, so it remains an ideal candidate for mapping generation using Mapping Architect for
Visio.
8|
Mapping Template
Visio Template
The Mapping Architect for Visio template to generate mappings looks like this:
As can be seen the structure is identical to the PowerCenter mapping. Only the components
that are different in each mapping are parameterized in the template.
Rule Types
The links between the transformations contain rules that can have different types. This example
template uses one additional type of rule when compared to the basic example:
Type Description Where Used (examples)
Parameter Use a template parameter to specify the actual rules Between H-source
to be applied during mapping generation. In this qualifier and joiner,
example these rules are used to propagate a between router and DT_D
variable number of named ports. target definition.
Template Parameters
The template uses parameters to generate the PowerCenter mappings. The additional
parameters used by this example are described in the table below.
Name Description Where Used
1. $PK_COLUMNS_IN Contains names of primary key columns
Rule_SQ_H_Joiner
$ that need to be selected from the H-table.
2. $PK_COLUMNS_O Contains names of primary key columns
UT$ that need to be loaded to the DT-table for Rule_Delete_DT
deleted records.
Example Files
The following files can be used to generate the example mapping based on the table definitions
of the basic design. The mapping itself is also included for reference.
File Description
1. Visio template file
H_DT_Extended.vsd
H_DT_Extended.xml
H_DT_Extended_par
am_DATASET.xml
TB_DATASET_H_DT_
Extended.XML
10 |