odi business rules

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 Initial Draft Gourav Atalkar 24-Aug-2011 0.1 Review 1 st Amit Sharma 24-Aug-2011 Business Intelligence Solutions Providers | ODI Business Rule implementations 1

Upload: amit-sharma

Post on 05-Mar-2015

11.061 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: ODI Business Rules

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 Initial Draft Gourav Atalkar 24-Aug-2011

0.1 Review 1st Amit Sharma 24-Aug-2011

Business Intelligence Solutions Providers | ODI Business Rule implementations 1

Page 2: ODI Business Rules

Table of Contents

1) List of business rules to implement 3

2) Introduction to source database Table 9

3) Target Table details 4

4) Target to Source table Mapping with business rules 6

5) Creating sequences for generating identity column 10

6) Creating User Function for generating City Type code, Weekend Flag, Fiscal

Quarter and Fiscal Month 15

7) Creating interface for loading the Time dimension data 19

8) Creating interface for loading the Store dimension data 24

9) Creating interface for loading the Product dimension data 30

10) Creating interface for loading the fact table data 34

Business Intelligence Solutions Providers | ODI Business Rule implementations 2

Page 3: ODI Business Rules

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 3

Page 4: ODI Business Rules

2) Target Table details :

Time Dimension:

Store Dimension:

Business Intelligence Solutions Providers | ODI Business Rule implementations 4

Page 5: ODI Business Rules

Product Dimension:

Fact Table:

Business Intelligence Solutions Providers | ODI Business Rule implementations 5

Page 6: ODI Business Rules

3) Target to Source table Mapping with business rules:

Time Dimension:

Target Table: Time Dimension Source Table: All_ recordsS No.

Column Name Data Type Derivation Logic S No

.

Column Name

Data Type

1 Time_id Number(38,0) Sequence 1 incremental Number(38,0)

2 year VARCHAR2(35 BYTE) Direct Mapping 2 year VARCHAR2(35 BYTE)

3 Quarter VARCHAR2(35 BYTE) Direct Mapping 3 Quarter VARCHAR2(35 BYTE)

4 Month_number NUMBER(35,0) Direct Mapping 4 Month_number NUMBER(35,0)

5 Month_name VARCHAR2(35 BYTE) Direct Mapping 5 Month_name VARCHAR2(35 BYTE)

6 Day_name VARCHAR2(35 BYTE) Direct Mapping 6 Day_name VARCHAR2(35 BYTE)

7 Created_by VARCHAR2(35 BYTE) 7 Genrated VARCHAR2(35 BYTE)

8 Created_date DATE SYSDATE 8 Genrated DATE

9 Updated_by VARCHAR2(35 BYTE) 9 Genrated VARCHAR2(35 BYTE)

10 Updated_date DATE SYSDATE 10 Genrated DATE

11 Other_date DATE 11 Genrated DATE

Business Intelligence Solutions Providers | ODI Business Rule implementations 6

Page 7: ODI Business Rules

12 Weekend_Flag VARCHAR2(35 BYTE) CASEWHEN Day_name='Sunday' then 'SUN' WHEN Day_name='Saturday' then 'SAT' ELSE 'OTHERS' END

12 Genrated VARCHAR2(35 BYTE)

13 Fiscal_year VARCHAR2(35 BYTE) 13 Genrated VARCHAR2(35 BYTE)

14 Fiscal_Qtr VARCHAR2(35 BYTE) CASEWHEN 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

14 Genrated VARCHAR2(35 BYTE)

15 Fiscal_month VARCHAR2(35 BYTE) CASEWHEN 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

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 Source Table: All_ recordsS No.

Column Name Data Type Derivation Logic S No

.

Column Name

Data Type

1 Store_id Number(38,0) Sequence 1 incremental Number(38,0)

2 Region VARCHAR2(35 BYTE) Direct Mapping 2 Region VARCHAR2(35 BYTE)

3 Territory VARCHAR2(35 BYTE) Direct Mapping 3 Territory VARCHAR2(35 BYTE)

4 Country NUMBER(35,0) Direct Mapping 4 Country NUMBER(35,0)

5 Store_type VARCHAR2(35 BYTE) Direct Mapping 5 Store_type VARCHAR2(35 BYTE)

6 Store_name VARCHAR2(35 BYTE) Direct Mapping 6 Store_name VARCHAR2(35 BYTE)

7 Street address VARCHAR2(35 BYTE) Direct Mapping 7 Street address VARCHAR2(35 BYTE)

8 City DATE Direct Mapping 8 City DATE

9 State VARCHAR2(35 BYTE) Direct Mapping 9 State VARCHAR2(35 BYTE)

10 Postal Code VARCHAR2(35 BYTE) Direct Mapping 10 Postal Code DATE

Business Intelligence Solutions Providers | ODI Business Rule implementations 7

Page 8: ODI Business Rules

11 Created_By VARCHAR2(35 BYTE) name 11 Genrated DATE

12 Created_date DATE SYSDATE 12 Genrated VARCHAR2(35 BYTE)

13 Update_by VARCHAR2(35 BYTE) name 13 Genrated VARCHAR2(35 BYTE)

14 Updated_date DATE SYSDATE 14 Genrated VARCHAR2(35 BYTE)

15 Custom_store_code VARCHAR2(35 BYTE) CONCAT(SUBSTR(FRI."Country",1,3),FRI."Store Name")

15 Genrated VARCHAR2(35 BYTE)

16 Store_code NUMBER(35,0) Direct Mapping 16 Store_code NUMBER(35,0)

Product Dimension:

Target Table: Product Dimension Source Table: All_ recordsS No.

Column Name Data Type Derivation Logic S No.

Column Name Data Type

1 Product_id Number(38,0) Sequence 1 incremental Number(38,0)

2 Product_Line VARCHAR2(35 BYTE) Direct Mapping 2 Product_Line VARCHAR2(35 BYTE)

3 Product Family VARCHAR2(35 BYTE) Direct Mapping 3 Product Family VARCHAR2(35 BYTE)

4 Product Category NUMBER(35,0) Direct Mapping 4 Product Category NUMBER(35,0)

5 Product Name VARCHAR2(35 BYTE) Direct Mapping 5 Product Name VARCHAR2(35 BYTE)

6 Product Publisher VARCHAR2(35 BYTE) Direct Mapping 6 Product Publisher VARCHAR2(35 BYTE)

7 Created By VARCHAR2(35 BYTE) Direct Mapping 7 Created By VARCHAR2(35 BYTE)

8 Created Date DATE Direct Mapping 8 Created Date DATE

9 Updated By VARCHAR2(35 BYTE) Direct Mapping 9 Updated By VARCHAR2(35 BYTE)

10 Updated Date DATE Direct Mapping 10 Updated Date DATE

11 Product_code Number Direct Mapping 11 Product_code Number

Fact Table:

Target Table: Product Dimension Source Table: All_ recordsS No.

Column Name Data Type Derivation Logic S No.

Column Name Data Type

1 Product_code Number(38,0) Sequence 1 incremental Number(38,0)

2 Day_code VARCHAR2(35 BYTE) Direct Mapping 2 Product_Line VARCHAR2(35 BYTE)

3 Store_code VARCHAR2(35 BYTE) Direct Mapping 3 Product Family VARCHAR2(35 BYTE)

4 Unit Sales NUMBER(35,0) Direct Mapping 4 Product Category NUMBER(35,0)

5 Amount Sales VARCHAR2(35 BYTE) Direct Mapping 5 Product Name VARCHAR2(35 BYTE)

4) Creating Sequence for adding unique id to time, store and product dimension :

Business Intelligence Solutions Providers | ODI Business Rule implementations 8

Page 9: ODI Business Rules

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 9

Page 10: ODI Business Rules

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

Page 11: ODI Business Rules

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

Page 12: ODI Business Rules

Open Designer. Click the Projects tab and expand: Project > DATA WAREHOUSE PROJECT. Right-click 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

Page 13: ODI Business Rules

Same way we have to create other to sequences also.

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

Business Intelligence Solutions Providers | ODI Business Rule implementations 13

Page 14: ODI Business Rules

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.

CASEWHEN $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

Page 15: ODI Business Rules

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.

CASEWHEN $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

Page 16: ODI Business Rules

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.

CASEWHEN $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

Page 17: ODI Business Rules

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.

CASEWHEN $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

Page 18: ODI Business Rules

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

Page 19: ODI Business Rules

Need to map other target column with user functions

Business Intelligence Solutions Providers | ODI Business Rule implementations 19

Page 20: ODI Business Rules

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

Page 21: ODI Business Rules

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

Result:

Business Intelligence Solutions Providers | ODI Business Rule implementations 21

Page 22: ODI Business Rules

7) Creating Interface for loading Store dimension data:

Business Intelligence Solutions Providers | ODI Business Rule implementations 22

Page 23: ODI Business Rules

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

Page 24: ODI Business Rules

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

Page 25: ODI Business Rules

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

Business Intelligence Solutions Providers | ODI Business Rule implementations 25

Page 26: ODI Business Rules

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

Page 27: ODI Business Rules

Result:

Business Intelligence Solutions Providers | ODI Business Rule implementations 27

Page 28: ODI Business Rules

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

Page 29: ODI Business Rules

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

Page 30: ODI Business Rules

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

Page 31: ODI Business Rules

Go to flow tab and specify the proper knowledge modules

Now we will execute it

Business Intelligence Solutions Providers | ODI Business Rule implementations 31

Page 32: ODI Business Rules

Result:

9)Creating Interface for loading Fact table data:

Business Intelligence Solutions Providers | ODI Business Rule implementations 32

Page 33: ODI Business Rules

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

Page 34: ODI Business Rules

Go to flow tab and specify the proper knowledge modules

Now we will execute it

Business Intelligence Solutions Providers | ODI Business Rule implementations 34

Page 35: ODI Business Rules

Result:

Business Intelligence Solutions Providers | ODI Business Rule implementations 35