Sei sulla pagina 1di 14

BANGALORE TECHNICAL TRAININGS Onlinetrainingsbglr@gmail.

com +917411642061

Lab 6
Flat File Wizard and Filter Transformation

Lab at a Glance................................................................2 Objectives..............................................................2 Summary................................................................2 Duration.................................................................3 Exercises.........................................................................4 Exercise 1: Import Source and Target....................4 Exercise 2: Create the Mapping.............................6 Exercise 3: Create and Run the Workflow............11

PowerCenter 9.x Level I Developer Lab Guide

6-1

Lab 6. Flat File Wizard and Filter Transformation

Lab at a Glance
The exercises in this lab are designed to walk the student through the process of importing and analyzing a flat file source using the Flat File Wizard. The student will also learn how to use the Filter transformation.

Objectives
After completing the lab, the student will be able to: Use the Flat File wizard. Create a Filter transformation.

Summary
In this lab, the student will create a mapping (and associated workflow) to extract data from a flat file that contains date records. An example of data from the flat file follows:

The mapping must transform the data and load it into a target table as follows:

In addition, the mapping must filter the data for only those dates after 12/04/1999.

6-2

PowerCenter 9.x Level I Developer Lab Guide

Lab 6. Flat File Wizard and Filter Transformation

The final mapping should look as follows:

Duration
This lab should take approximately 40 minutes.

PowerCenter 9.x Level I Developer Lab Guide

6-3

Lab 6. Flat File Wizard and Filter Transformation

Exercises
Exercise 1: Import Source and Target
Step 1. Import the file.

6-4

PowerCenter 9.x Level I Developer Lab Guide

Lab 6. Flat File Wizard and Filter Transformation

In the Designer, open the Source Analyzer by clicking the Source Analyzer
Analyzer.

button or by selecting Tools | Source

Select Sources | Import From File. The Open Flat File dialog box appears.

Change the Files of type: to All Files(*.*). Locate the directory where the flat file resides typically C:\pmfiles\SrcFiles, although your instructor can confirm. Select the flat tile TIME.txt. Click OK. The Flat File Import Wizard appears. Ensure the Delimited radio button is selected (default). Select the Import field names from first line checkbox.

The first row in the TIME.txt file contains the column names. When this option is checked, the import automatically starts at row 2 and assumes that future extracts will start at row 2.

PowerCenter 9.x Level I Developer Lab Guide

6-5

Lab 6. Flat File Wizard and Filter Transformation

Step 2. Import the target table. Open the Warehouse Designer by clicking the Warehouse
Designer

button on the toolbar.

Select Targets | Import From Database. Connect to the target ODBC connection (tdbuxx - where xx is the assigned student number). Expand the TDBUxx schema and TABLES node. Select ODS_TIME. Click OK. The ODS_TIME target table should look as follows:

Save the repository.

Exercise 2: Create the Mapping


Step 1. Create a mapping. Open the Mapping Designer by clicking on the Mapping Designer button Create a new mapping called m_ODS_TIME_xx. Step 2. Add source and target transformations. From the FlatFile category under the Sources node, dragand-drop the TIME source definition into the Mapping Designer workspace. From the Targets node, drag-and-drop ODS_TIME into the Mapping Designer workspace. Step 3. Create an Expression transformation. Create a new Expression transformation. Select all ports within the sq_TIME source qualifier, then drag-and-drop them onto the Expression transformation.

6-6

PowerCenter 9.x Level I Developer Lab Guide

Lab 6. Flat File Wizard and Filter Transformation

Double-click on the header of the Expression transformation. The Edit Transformations dialog appears. Click the Rename button. Enter exp_ODS_TIME in the Transformation Name field and click the OK button. Click on the Ports tab. Highlight the third port, QUARTER, then add the following ports by clicking the Add Port

button:

DATE_ID, Datatype=date/time, Prec=19(default), Port Type=Output Only MONTH_out, Datatype=string, Prec=3, Port Type=Output Only QUARTER_out, Datatype=string, Prec=2, Port Type=Output Only YEAR_out, Datatype=string, Prec=4, Port Type=Output Only

Since the last 2 new ports listed are close in datatype, port-type and formula to MONTH_out, you may optionally copy the MONTH_out port and paste-in 2 copies. Use the copy and paste icons to the right of the 'Add a new column' button. Be sure to alter the newly copied ports for port name, precision and formula, to be accurate for QUARTER_out and YEAR_out.

An expression will be needed for each of the above ports to derive the values. Open the Expression Editor and add expressions for each port as follows:
DATE_ID TO_DATE(DATE,DD-MON-YYYY) MONTH_out SUBSTR(DATE,4,3) QUARTER_out SUBSTR(QUARTER,6,1) YEAR_out SUBSTR(QUARTER,1,4)

Change the ports, DATE and QUARTER, to input only ports. The Ports tab of the exp_ODS_TIME expression should look as follows:

PowerCenter 9.x Level I Developer Lab Guide

6-7

Lab 6. Flat File Wizard and Filter Transformation

Click the OK button. The expression transformation should look as follows:

Step 4. Create a Filter transformation. Click on the Filter Transformation Transformation toolbar. button on the

Click and drag the pointer (which appears as crosshairs in the workspace) to the right of the exp_ODS_TIME expression. Drag and drop the following ports in the order specified from exp_ODS_TIME to the FILTRANS window:
DATE_ID DAY_OF_WEEK MONTH_out QUARTER_out YEAR_out

Double-click on the Filter transformation. The Edit Transformations dialog box appears. Click the Rename button and enter fil_ODS_TIME. Click on the Ports tab and rename the following ports:
MONTH_out = MONTH = QUARTER = YEAR

QUARTER_out YEAR_out

Click on the Properties tab.

6-8

PowerCenter 9.x Level I Developer Lab Guide

Lab 6. Flat File Wizard and Filter Transformation

Click on the down arrow to edit the Filter Condition:

To define a new filter condition, remove the default text, TRUE. Open the Expression Editor and click on the Ports tab to the right of the Functions tab.

Double-click on DATE_ID. Click the greater than or equals operator keypad. button on the

Click the Functions tab, expand the Conversion folder and double-click on To_Date. To complete the expression, type '12/04/1999', 'MM/DD/YYYY' between the parentheses. The final expression should look as follows:
DATE_ID >=TO_DATE('12/04/1999', 'MM/DD/YYYY')

Click on the Validate button to validate the filter condition. Click OK twice to save changes. The Filter transformation should look as follows:

PowerCenter 9.x Level I Developer Lab Guide

6-9

Lab 6. Flat File Wizard and Filter Transformation

Step 5. Link the Target transformation. Right-click in the workspace and select Autolink Select fil_ODS_TIME in the From Transformation field and ODS_TIME in the To Transformations field. Make sure that the Name radio button is selected in the By field:

Click OK. All ports should be linked between these two transformations:

Validate the mapping by selecting Mapping |Validate. Remember to check the Validate tab in the Output window for the results. Save the repository. The completed mapping should look as follows:

6 - 10

PowerCenter 9.x Level I Developer Lab Guide

Lab 6. Flat File Wizard and Filter Transformation

Exercise 3: Create and Run the Workflow


In this exercise, the student will create a workflow to run and test the new mapping. Step 1. Start the Workflow Manager. Start the Workflow Manager. Connect to the repository. Open the studentxx folder. Step 2. Create a workflow. Select Workflows | Create to create a new workflow. Name the workflow wf_ODS_TIME_xx. Create a session task for the m_ODS_TIME_xx mapping called s_m_ODS_TIME_xx. Double-click on the session task. The Edit Tasks dialog box appears.

Select the Mapping tab. In the Navigator window, select the source SQ_TIME. Under Properties, TIME File Reader, Source filename, enter TIME.txt.

In the Navigator window, select the target ODS_TIME. Under Connections, click on the down arrow select native_target_xx and click OK. ,

Under Properties, the Target load type should be


6 - 11

PowerCenter 9.x Level I Developer Lab Guide

Lab 6. Flat File Wizard and Filter Transformation

defaulted to Normal. Scroll down to select the Truncate target table option.

Click OK to close the Edit Tasks dialog box.

Save the repository. Link Start to s_m_ODS_TIME_xx.

Save, validate and start the workflow. Monitor and review the results for s_m_ODS_TIME_xx in the Workflow Monitor. Step 3. Verify results - session properties. By using the date 12/04/1999 as a filter, the ODS_TIME_xx table should contain 1489 rows:

Step 4. Verify results - session transformation statistics.

Step 5. Verify results preview data. Return to the Designer and go to the Warehouse

6 - 12

PowerCenter 9.x Level I Developer Lab Guide

Lab 6. Flat File Wizard and Filter Transformation

Designer. Right-click the ODS_TIME target definition header and select Preview Data The Preview Data dialog box appears.

Select the odbc_target ODBC data source connection from the pull-down list. Enter the username and password assigned by the instructor should be tdbuxx/tdbuxx (where xx is the assigned student number). Click on Connect. The results appear in the bottom half of the dialog box. The default number of returned rows is 100. By default, 100 rows are returned. In this Lab Guide, only some rows are shown. Here is an excerpt from the middle of the results.

PowerCenter 9.x Level I Developer Lab Guide

6 - 13

Lab 6. Flat File Wizard and Filter Transformation

6 - 14

PowerCenter 9.x Level I Developer Lab Guide

Potrebbero piacerti anche