You are on page 1of 35

Document: Oracle Data Integrator 11g (11.1.1.

5) ODI Business Rules Implementation

Description:
(This Document explains the basic ETL Rule implementation using sequences and User functions with mapping tables.)

History:
Version Description Change Author Publish Date

0.1 0.1

Initial Draft Review 1st

Gourav Atalkar Amit Sharma

24-Aug-2011 24-Aug-2011

Business Intelligence Solutions Providers

ODI Business Rule implementations

Table of Contents
1)

List of business rules to implement


2)

3 9 4 6 10

Introduction to source database Table

3)

Target Table details Target to Source table Mapping with business rules Creating sequences for generating identity column

4)

5)

6)

Creating User Function for generating City Type code, Weekend Flag, Fiscal Quarter and Fiscal Month 15 19 24 30 34

7)

Creating interface for loading the Time dimension data Creating interface for loading the Store dimension data Creating interface for loading the Product dimension data Creating interface for loading the fact table data

8)

9)

10)

Business Intelligence Solutions Providers

ODI Business Rule implementations

1) List of business rules to implement :


Split record and store in different table.
Creating Sequences for adding key column to all dimension tables.

In All dimension insert following fields Created By Created Date Update By Update Date

Add weekend flag to time dimension table : Sat/Sun/Others Add other Date column to target table time dimension Add fiscal year, Fiscal month and fiscal quarter to time dimension Create custom store code [city(3) + store code]
Order the store dimension by postal code.

For implementing these all requirement we have one source database table inside MS SQL server 2000 and target tables we have created inside the oracle 11g according distribution of the columns from the source. Below is the description about the source and target tables

2) Introduction to source database Table:

Business Intelligence Solutions Providers

ODI Business Rule implementations

2)

Target Table details :

Time Dimension:

Store Dimension:

Business Intelligence Solutions Providers

ODI Business Rule implementations

Product Dimension:

Fact Table:

Business Intelligence Solutions Providers

ODI Business Rule implementations

3)

Target to Source table Mapping with business rules:

Time Dimension: Target Table: Time Dimension S Column Name Data Type
No . 1 2 3 4 5 6 7 8 9 10 11 Time_id year Quarter Month_number Month_name Day_name Created_by Created_date Updated_by Updated_date Other_date
Number(38,0) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) NUMBER(35,0) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) DATE VARCHAR2(35 BYTE) DATE DATE SYSDATE SYSDATE

Derivation Logic
Sequence Direct Mapping Direct Mapping Direct Mapping Direct Mapping Direct Mapping

Source Table: All_ records S Column Data Type No Name .


1 2 3 4 5 6 7 8 9 10 11 incremental year Quarter Month_number Month_name Day_name Genrated Genrated Genrated Genrated Genrated
Number(38,0) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) NUMBER(35,0) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) DATE VARCHAR2(35 BYTE) DATE DATE

Business Intelligence Solutions Providers

ODI Business Rule implementations

12

Weekend_Flag

VARCHAR2(35 BYTE)

CASE WHEN Day_name='Sunday' then 'SUN' WHEN Day_name='Saturday' then 'SAT' ELSE 'OTHERS' END CASE WHEN Month_name=Apr' then 'Q1' WHEN Month_name=May' then 'Q1' WHEN Month_name=Jun' then 'Q1' WHEN Month_name=Jul' then 'Q2' WHEN Month_name=Aug' then 'Q2' WHEN Month_name=Sep ' then 'Q2' WHEN Month_name=Oct' then 'Q3' WHEN Month_name=Nov' then 'Q3' WHEN Month_name=Dec' then 'Q3' WHEN Month_name=Jan' then 'Q4' WHEN Month_name=Feb' then 'Q4' WHEN Month_name=Mar' then 'Q4' ELSE 'NULL' END CASE WHEN Month_name=Apr' then 'month 1' WHEN Month_name=May' then 'Month 2' WHEN Month_name=Jun' then 'Month 3' WHEN Month_name=Jul' then 'Month 4' WHEN Month_name=Aug' then ' Month 5' WHEN Month_name=Sep ' then ' Month 6' WHEN Month_name=Oct' then ' Month 7' WHEN Month_name=Nov' then ' Month 8' WHEN Month_name=Dec' then ' Month 9' WHEN Month_name=Jan' then 'Month 10' WHEN Month_name=Feb' then 'Month 11' WHEN Month_name=Mar' then 'Month 12' ELSE 'NULL' END

12

Genrated

VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE)

13 14

Fiscal_year Fiscal_Qtr

VARCHAR2(35 BYTE) VARCHAR2(35 BYTE)

13 14

Genrated Genrated

15

Fiscal_month

VARCHAR2(35 BYTE)

15

Genrated

VARCHAR2(35 BYTE)

16

Day_code

NUMBER(35,0)

Direct Mapping

16

Day_code

NUMBER(35,0)

Store Dimension: Target Table: Store Dimension S Column Name Data Type
No . 1 2 3 4 5 6 7 8 9 10 Store_id Region Territory Country Store_type Store_name Street address City State Postal Code
Number(38,0) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) NUMBER(35,0) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) DATE VARCHAR2(35 BYTE) VARCHAR2(35 BYTE)

Derivation Logic
Sequence Direct Mapping Direct Mapping Direct Mapping Direct Mapping Direct Mapping Direct Mapping Direct Mapping Direct Mapping Direct Mapping

Source Table: All_ records S Column Data Type No Name .


1 2 3 4 5 6 7 8 9 10 incremental Region Territory Country Store_type Store_name Street address City State Postal Code
Number(38,0) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) NUMBER(35,0) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) DATE VARCHAR2(35 BYTE) DATE

Business Intelligence Solutions Providers

ODI Business Rule implementations

11 12 13 14 15 16

Created_By Created_date Update_by Updated_date Custom_store_code Store_code

VARCHAR2(35 BYTE) DATE VARCHAR2(35 BYTE) DATE VARCHAR2(35 BYTE) NUMBER(35,0)

name
SYSDATE

11 12 13 14 15 16

Genrated Genrated Genrated Genrated Genrated Store_code

DATE VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) NUMBER(35,0)

name
SYSDATE CONCAT(SUBSTR(FRI."Country",1,3),FRI." Store Name")

Direct Mapping

Product Dimension: Target Table: Product Dimension S Column Name Data Type
No . 1 2 3 4 5 6 7 8 9 10 11 Product_id Product_Line Product Family Product Category Product Name Product Publisher Created By Created Date Updated By Updated Date Product_code
Number(38,0) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) NUMBER(35,0) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) DATE VARCHAR2(35 BYTE) DATE Number

Derivation Logic
Sequence Direct Mapping Direct Mapping Direct Mapping Direct Mapping Direct Mapping Direct Mapping Direct Mapping Direct Mapping Direct Mapping Direct Mapping

Source Table: All_ records S Column Name Data Type No.


1 2 3 4 5 6 7 8 9 10 11 incremental Product_Line Product Family Product Category Product Name Product Publisher Created By Created Date Updated By Updated Date Product_code
Number(38,0) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) NUMBER(35,0) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) DATE VARCHAR2(35 BYTE) DATE Number

Fact Table: Target Table: Product Dimension S Column Name Data Type
No . 1 2 3 4 5 Product_code Day_code Store_code Unit Sales Amount Sales
Number(38,0) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) NUMBER(35,0) VARCHAR2(35 BYTE)

Derivation Logic
Sequence Direct Mapping Direct Mapping Direct Mapping Direct Mapping

Source Table: All_ records S Column Name Data Type No.


1 2 3 4 5 incremental Product_Line Product Family Product Category Product Name
Number(38,0) VARCHAR2(35 BYTE) VARCHAR2(35 BYTE) NUMBER(35,0) VARCHAR2(35 BYTE)

Creating Sequence for adding unique id to time, store and product dimension :
4) Business Intelligence Solutions Providers | ODI Business Rule implementations 8

Step: 1) Create and execute an ODI procedure that creates an Oracle native sequence. If not connected, connect to the Work Repository work repository (User: SUPERVISOR, Password: SUNOPSIS). Click the Designer tab.

Step: 2) In the Projects tab, expand: Project > DATA WAREHOUSE PROJECT. Right-click Procedures and select New Procedure. Name the new procedure: Generate_id_product. Set the Target technology to Oracle, as shown next. Click the Detail tab.

Step: 3) In the Details tab, select the Add command button. In the Name field, enter: Generate_id_product. In the Command on target tab, set the Technology field to Oracle. In the Schema drop-down list, select Orders. In the Command panel, enter the command, which creates the following sequence. Click the Save icon to save the procedure. Close the tab.

Business Intelligence Solutions Providers

ODI Business Rule implementations

Step: 4) Run the procedure Generate_id_product and verify the result of the execution in Operator.

Business Intelligence Solutions Providers

ODI Business Rule implementations

10

Step: 5) Open SQL Developer and expand: Administrator > Other Users > Orders > Sequences. Verify that your sequence SEQ_ PRODUCT_ID was created in RDBMS.

Step: 6) create a new Native Sequence in ODI.

Business Intelligence Solutions Providers

ODI Business Rule implementations

11

Open Designer. Click the Projects tab and expand: Project > DATA WAREHOUSE PROJECT. Rightclick Sequences and then select New Sequence.

Step: 7) Name the new sequence PRODUCT_SEQ. Select the Native Sequence check box. In the schema filed, select ORDERS. Click the browse icon. In the window that follows, select the GLOBAL context, and then select the native sequence SEQ_Product_ ID. Click OK. Your screen should look as shown next. Save the sequence, and then close the tab.

Business Intelligence Solutions Providers

ODI Business Rule implementations

12

Same way we have to create other to sequences also.

Creating User Function for generating City Type code, Weekend Flag, Fiscal Quarter and Fiscal Month :
5)

Business Intelligence Solutions Providers

ODI Business Rule implementations

13

Step: 1) Select project tab right click on user function and select new user function. In definition tab name box specify the name of user function group box specify the group of user function in syntax box specify the user function and parameter.

Step: 2) now go to the implementation tab select add button. In the implementation syntax box insert the logic for converting the country in different types. Select the technology to which you want to implement this code.
CASE WHEN $1 ='USA' then 'Type A' WHEN $1='Australia' then 'Type B' WHEN $1= 'JAPAN' then 'Type B' WHEN $1= 'Germany' then 'Type B' WHEN $1= 'Ireland' then 'Type B' WHEN $1= 'France' then 'Type B' WHEN $1='United Kingdom' then 'Type C' WHEN $1='Brazil' then 'Type C' WHEN $1= 'Norway' then 'Type C' WHEN $1= 'Sweden' then 'Type C' WHEN $1= 'Canada' then 'Type C' ELSE NULL END

Step: 3) Now we will create one more user function for adding weekend flag

Business Intelligence Solutions Providers

ODI Business Rule implementations

14

Step: 4) now go to the implementation tab select add button. In the implementation syntax box insert the logic for generating weekend flag from the days.
CASE WHEN $1 ='Sunday' then 'SUN' WHEN $1=Saturday then 'SAT' ELSE 'OTHERS' END

Step: 5) Creating Fiscal Quarter User function

Business Intelligence Solutions Providers

ODI Business Rule implementations

15

Step: 6) now go to the implementation tab select add button. In the implementation syntax box insert the logic for converting the Month in different Quarters.
CASE WHEN $1 ='April' then 'Qtr1' WHEN $1='May' then 'Qtr1' WHEN $1='June' then 'Qtr1' WHEN $1='July' then 'Qtr2' WHEN $1='August' then 'Qtr2' WHEN $1='September' then 'Qtr2' WHEN $1='October' then 'Qtr3' WHEN $1='November' then 'Qtr3' WHEN $1='December' then 'Qtr3' WHEN $1='January' then 'Qtr4' WHEN $1='February' then 'Qtr4' WHEN $1='March' then 'Qtr4' ELSE 'OTHERS' END

Step: 6) Creating Fiscal Month User function

Business Intelligence Solutions Providers

ODI Business Rule implementations

16

Step: 6) now go to the implementation tab select add button. In the implementation syntax box insert the logic for converting the Month in different Fiscal month.
CASE WHEN $1 ='April' then 'month1' WHEN $1='May' then 'month2' WHEN $1='June' then 'month3' WHEN $1='July' then 'month4' WHEN $1='August' then 'month5' WHEN $1='September' then 'month6' WHEN $1='October' then 'month7' WHEN $1='November' then 'month8' WHEN $1='December' then 'month9' WHEN $1='January' then 'month10' WHEN $1='February' then 'month11' WHEN $1='March' then 'month12' ELSE 'OTHERS' END

6)

Creating Interface for loading Time dimension data:

Step: 1) Select interface tab in project and right click and new interface specify the name of the interface in definition tab and move to mapping tab.
Business Intelligence Solutions Providers | ODI Business Rule implementations 17

Step: 2) drag and drop the source and target tables from the model tab.

We need to map source and target column according mapping tables. Select the first column in target table and select Expression editor button open it and specify the sequence for generating primary key column.

Business Intelligence Solutions Providers

ODI Business Rule implementations

18

Need to map other target column with user functions

Business Intelligence Solutions Providers

ODI Business Rule implementations

19

Similarly we need to place other user function and parameter in the target column.

Specify the proper IKM and set up the property according requirement

Business Intelligence Solutions Providers

ODI Business Rule implementations

20

Now we will execute it and load the data to target table time.

Result:

Business Intelligence Solutions Providers

ODI Business Rule implementations

21

7)

Creating Interface for loading Store dimension data:

Business Intelligence Solutions Providers

ODI Business Rule implementations

22

Step: 1) Select interface tab in project and right click and new interface specify the name of the interface in definition tab and move to mapping tab.

Step: 2) drag and drop the source and target tables from the model tab.

We need to map source and target column according mapping tables. Select the first column in target table and select Expression editor button open it and specify the sequence for generating primary key column.

Business Intelligence Solutions Providers

ODI Business Rule implementations

23

Need to map other target column with user functions first we will map custom store code where we have the first three character of country and store name.

Business Intelligence Solutions Providers

ODI Business Rule implementations

24

Now we will map Country type column by previously created user function col_type

Business Intelligence Solutions Providers

ODI Business Rule implementations

25

After mapping all columns successfully we will move to flow tab for specifying the loading knowledge module and integrating knowledge module.

Specify the proper IKM and set up the property according requirement

Now we will execute it and load the data to target table time

Business Intelligence Solutions Providers

ODI Business Rule implementations

26

Result:

Business Intelligence Solutions Providers

ODI Business Rule implementations

27

8)

Creating Interface for loading Product dimension data:

Step: 1) Select interface tab in project and right click and new interface specify the name of the interface in definition tab and move to mapping tab.

Step: 2) drag and drop the source and target tables from the model tab.

Business Intelligence Solutions Providers

ODI Business Rule implementations

28

We need to map source and target column according mapping tables. Select the first column in target table and select Expression editor button open it and specify the sequence for generating primary key column

Business Intelligence Solutions Providers

ODI Business Rule implementations

29

Change the execution location and the key check box and not null box need to check.

Need to map other target column with source according to mapping table.

Business Intelligence Solutions Providers

ODI Business Rule implementations

30

Go to flow tab and specify the proper knowledge modules

Now we will execute it

Business Intelligence Solutions Providers

ODI Business Rule implementations

31

Result:

9)Creating Interface for loading Fact table data:

Business Intelligence Solutions Providers

ODI Business Rule implementations

32

Step: 1) Select interface tab in project and right click and new interface specify the name of the interface in definition tab and move to mapping tab.

Step: 2) drag and drop the source and target tables from the model tab.

We need to map source and target column according mapping tables.

Business Intelligence Solutions Providers

ODI Business Rule implementations

33

Go to flow tab and specify the proper knowledge modules

Now we will execute it

Business Intelligence Solutions Providers

ODI Business Rule implementations

34

Result:

Business Intelligence Solutions Providers

ODI Business Rule implementations

35

You might also like