Working with Flat File Source, LookUp & Filter Transformation
This tutorial shows the process of creating an Informatica PowerCenter mapping and workflow which pulls data from Flat File data sources and use LookUp and Filter Transformation.
For the demonstration purpose lets consider a flat file with the list of existing and potential customers. We need to create a mapping which loads only the potential customers but not the existing customers to a relational target table.
While creating the mapping we will cover the following.
- Create a mapping which reads from a flat file and creates a relational table consisting of new customers
- Analyze a fixed width flat file
- Configure a Connected Lookup transformation
- Use a Filter transformation to exclude records from the pipeline.
I. Connect to the Repository
- Connect to the repository.
- Open the folder where you need the mapping built.
II. Analyze the source files
- Import the flat file definition (say Nielsen.dat) into the repository.
- Select SOURCES | IMPORT FROM FILE from the menu.
- Select Nielsen.dat from the source file directory path. Hint : Be sure to set the Files of type: to All files (*.*) from the pull-down list, before clicking on OK.
- Set the following options in the Flat File Wizard:
- Select Fixed Width and check the Import field names from first line box. This option will extract the field names from the first record in the file.
- Create a break line or separator between the fields.
- Click on NEXT to continue.
- Refer Appendix A to see the structure of NIELSEN.DAT flat file.
- Change field name St to State and Code to Postal_Code. Note : The physical data file will be present on the Server. At runtime, when the Server is ready to process the data (which is now defined by this new source definition called Nielsen.dat) it will look for the flat file that contains the data in Nielsen.dat.
- Click Finish.
- Name the new source definition NIELSEN. This is the name that will appear as metadata in the repository, for the source definition.
III. Design the Target Schema
Assumption: The target table does not exist in the database
- Switch to Target Designer.
- Select EDIT | CLEAR if necessary to clear the workspace. Any objects you clear from the workspace will still be available for use in Designer’s Navigator Window, in the Targets node.
- Drag the NIELSEN source definition from the Navigator Window into the workspace to automatically create a target table definition. You have just created a target definition based on the structure of the source file definition. You now need to edit the target table definition.
- Rename the table as Tgt_New_Cust_x.
- Enter the field names as mentioned in the Figure below .Change the Key Type for Customer_ID to Primary Key. The Not Null option will automatically be checked. Save the repository.
- The target table definition should look like this
- Create the physical table in the Oracle Database so that you can load data. Hint : From the Edit table properties in Target designer, change the database type to Oracle.
IV. Create the mapping and drag the Source and Target
- Create a new mapping with the name M_New_Customer_x
- Drag the source into the Mapping Designer workspace. The SourceQualifier should be automatically created.
- Rename the Source Qualifier as SQ_NIELSEN_x
- Drag the target (Tgt_New_Cust_x) into the Mapping Designer workspace
V. Create a Lookup Transformation
- Select TRANSFORMATION | CREATE.
- Select Lookup from the pull-down list.
- Name the new Lookup transformation Lkp_New_Customer_x.
- You need to identify the Lookup table in the Lookup transformation. Use the CUSTOMERS table from the source database to serve as the Lookup table and import it from the database.
- Select Import to import the Lookup table.
- Enter the ODBC Data Source, Username, Owner name, and Password for the Source Database and Connect.
- In the Select Tables box, expand the owner name until you see a TABLES listing.
- Select the CUSTOMERS table.
- Click OK.
- Click Done to close the Create Transformation dialog box. Note : All the columns from the CUSTOMERS table are seen in the transformation.
- Create an input-only port in Lkp_New_Customer_x to hold the Customer_Id value, coming from SQ_NIELSEN_x .
- Highlight the Cust_Id column from the SQ_NIELSEN_x
- Drag/drop it to Lkp_New_Customer_x.
- Double-click on Lkp_New_Customer_x to edit the Lookup transformation.
- Click the Ports tab, make Cust_Id an input-only port.
- Make CUSTOMER_Id a lookup and output port.
- Create the condition for lookup.
- Click the Condition Tab.
- Click on the icon.
- Add the lookup condition: CUSTOMER_ID = Cust_Id.
Note : Informatica takes its ‘best guess’ at the lookup condition you intend, based on data type and precision of the ports now in the Lookup transformation.
- Click the Properties tab.
- At line 6 as shown in the figure below, note the Connection Information.
VI. Create a Filter Transformation
- Create a Filter transformation that will filter through those records that do not match the lookup condition and name it Fil_New_Cust_x.
- Drag all the ports from Source Qualifier to the new Filter. The next step is to create an input-only port to hold the result of the lookup.
- Highlight the CUSTOMER_ID port from Lkp_New_Customer_x .
- Drag it to an empty port in Fil_New_Cust_x .
- Double-click Fil_New_Cust_x to edit the filter.
- Click the Properties tab.
- Enter the filter condition: ISNULL(CUSTOMER_ID). This condition will allow only those records whose value for CUSTOMER_ID is = null, to pass through the filter.
- Click OK twice to exit the transformation.
- Link all ports except CUSTOMER_ID from the Filter to the Target table.
Hint : Select the LAYOUT | AUTOLINK menu options, or right-click in the workspace background, and choose Auto link. In the Auto link box, select the Name radio button. This will link the corresponding columns based on their names.
- Click OK.
- Save the repository.
- Check the Output window to verify that the mapping is valid.
- Given below is the final mapping.
VII. Create the Workflow and Set Session Tasks Properties
- Launch the Workflow Manager and connect to the repository.
- Select your folder.
- Select WORKFLOWS | CREATE to create a Workflow as wf_New_Customer_x.
- Select TASKS | CREATE to d create a Session Task as s_New_Customer_x.
- Select the M_New_Customer_x mapping.
- Set the following options in the Session Edit Task:
- Select the Properties tab. Leave all defaults.
- Select the Mapping tab.
- Select the Source folder. On the right hand side, under Properties, verify the attribute settings are set to the following:
- Source Directory path = $PMSourceFileDir\
- File Name = Nielsen.dat (Use the same case as that present on the server)
- Source Type: Direct
Note : For the session you are creating, the Server needs the exact path, file name and extension for the file as it resides on the Server, to use at run time
- Click on the Set File Properties button.
- Click on Advanced.
- Check the Line sequential file format check box.
- Select the Targets folder.
- Under Connections on the right hand side, Select the value of
Target Relational Database Connection.
- Under Connections on the right hand side, Select the value of
- In the Transformations Folder, Select the Lkp_New_Customer transformation.
- On the right hand side, in Connections, Select the Relational Database Connection for the Lookup Table. Figure
- Select the Source folder. On the right hand side, under Properties, verify the attribute settings are set to the following:
- Run the Workflow.
- Monitor the Workflow.
- View the Session Details and Session Log.
- Verify the Results from the target table by running the query SELECT * FROM Tgt_New_Cust_x;
Video Tutorial
Hope you enjoyed this tutorial, Please let us know if you have any difficulties in trying out these exercise.