Mappings > Mappings > Mapping tutorial

Mapping tutorial

The following tutorial describes how to create a simple mapping, save and validate the mapping, and create a mapping task.
For this tutorial, you have a file that contains U.S. customer account information. You want to create a file that contains customer account information for a specific state.
In the mapping, you define the following components:
You create parameters in the mapping so that you can use the same mapping task to create files for each state. You create the following parameters:
After you define the mapping, you create a mapping task that is based on the mapping. When you run the mapping task, you specify values for the target object parameter and the filter parameter. The mapping task then writes the data to the specified target based on the specified state.
The mapping tutorial includes the following steps:
  1. 1. Create a mapping.
  2. 2. Configure a source. Specify the name of the source object and the connection to use.
  3. 3. Create a Filter transformation. Create a parameter in the Filter transformation to hold the state value.
  4. 4. Configure a target. Specify the connection to use and create a parameter for the target object.
  5. 5. Validate the mapping to be sure there are no errors. The mapping must be valid before you can run a task based on the mapping.
  6. 6. Create a task based on the mapping. The task includes parameters for the target object and state value, which you specify when you run the task.

Preparing for the mapping tutorial

Before you start the mapping tutorial, you need to download a sample file and set up a connection.
    1. Download the sample Account source file from the Informatica Cloud Community and save the file in a directory local to the Secure Agent. You can download the file from the following link:
    Sample Source File for the Mapping Tutorial
    2. Create a flat file connection for the directory that contains the saved sample Account source file.
    3. On the Explore page, create a project and name the project AccountsByState, and then create a folder in the project and name the folder Mappings.

Step 1. Create a mapping

In the following procedure, you create a mapping in the Mapping Designer to specify the source, filter, and target.
    1. To create a mapping, click New and then in the New Asset dialog box, click Mapping.
    The following image shows the New Asset dialog box with Mapping selected:
    In the New Assets dialog box, you can click Mapping to create a new mapping or you can select a template.
    2. Click Create. The Mapping Designer appears with a new mapping displayed in the mapping canvas.
    The following image shows a new mapping in the Mapping Designer:
    The Mapping Designer includes the mapping canvas, where you build your mapping, and the Properties panel, where you set properties for the mapping and each of the transformations in the mapping.
    3. In the Properties panel, enter m_Accounts_by_State for the mapping name.
    You can use underscores in mapping and transformation names, but do not use other special characters.
    Tip: Informatica recommends that you use a standard naming convention for objects. For example, begin all object names with an abbreviation of the object type so that mapping names begin with m_, Source transformation names begin with src_, parameter names begin with p_, and so on. Also, use names that explain the purpose of the object, for example, flt_Filter_by_State. A standard naming convention is particularly helpful when you are working with large, complex mappings so that you can easily identify the type and purpose of each object.
    The Properties panel shows the name and location of the mapping that you specified.
    4. To select a location for the mapping, browse to the folder you want the mapping to reside in, or use the default location.
    If the Explore page is currently active and a project or folder is selected, the default location for the asset is the selected project or folder. Otherwise, the default location is the location of the most recently saved asset.

Step 2. Configure a source

In the following procedure, you create a Source transformation to specify the source object.
When you design a mapping, the first transformation you configure is the Source transformation. You specify the source object in the Source transformation. The source object represents the source of the data that you want to use in the mapping. You add the source object at the beginning of mapping design because the source properties can affect the downstream data. For example, you might filter data at the source, which affects the data that enters downstream transformations.
Configure the sample Account flat file as the source object.
    1. On the mapping canvas, click the Source transformation to select it.
    2. In the Properties panel, click General and enter src_FF_Account for the Source transformation name.
    3. Specify which connection to use based on the source object. In this case, the source object is a flat file so the connection needs to be a flat file connection.
    Click Source and configure the following properties:
    Source detail
    Connection to the sample source file.
    Select the flat file connection that you set up before you started the tutorial.
    Source Type
    Source object or a parameter, which is a placeholder for the source object that you specify when you run a task based on the mapping.
    Select Single Object.
    Source object for the mapping.
    Click Select and navigate to the ACCOUNT.csv source file. Or, enter the full path to the source object and the source file name, for example, C:\Informatica\Tutorial\ACCOUNT.csv.
    If you want to view the data in the source file, you can click Preview Data.
    The following image shows the src_FF_Account details in the Properties panel:
    The Properties panel displays the source connection, source type, and source object for the FF_Account source transformation.
    To view the source fields and field metadata, click the Fields tab.
    4. To save the mapping and continue, click Save.

Step 3. Create a Filter transformation

In the following procedure, you create a Filter transformation to filter accounts based on the state in which each account is located. You also create a parameter to hold state values.
You want this mapping to run tasks that filter accounts based on specific states. To accomplish this, you add a Filter transformation to the data flow to capture state information. You then define a parameter in the filter condition to hold the state value. When you use a parameter, you can reuse the same mapping to create multiple tasks. You can specify a different state value for each task. Or you can use the same mapping task and change the value for state when you run the task.
The sample Account source file includes a State field. When you use the State field in the filter condition, you can write data to the target based on the state. For example, when you use State = MD as the condition, you include accounts based in Maryland in the data flow. When you use a parameter for the value of the filter condition, you can define the state that you want to use when you run the task.
Field rules define the fields that enter the transformation and how they are named. By default, all available fields are included in the transformation. You might want to exclude unnecessary fields when you have large source files. Or you might want to change the names of certain incoming fields, for example, when you have multiple sources in a mapping. Field rules are configured on the Incoming Fields tab. For this tutorial, do not configure field rules.
    1. To add a Filter transformation, drag a Filter transformation from the Transformation palette to the mapping canvas and drop it between the src_FF_Account Source transformation and the NewTarget transformation.
    Note: You might need to scroll through the Transformation palette to find the Filter transformation.
    When you drop a new transformation in between two transformations in the canvas, the new transformation is automatically linked in the data flow, as shown in the following image:
    The Source, Filter, and Target transformations display in a row in the mapping canvas with lines between the transformations, which illustrates that the transformations are connected in the data flow.
    When you link transformations, the downstream transformation inherits fields from the previous transformation.
    2. To configure the Filter transformation, select the Filter transformation on the mapping canvas.
    3. To name the Filter transformation, in the Properties panel, click General and enter flt_Filter_by_State for the Filter transformation name.
    4. To create a simple filter with a parameter for the value, click Filter. For the Filter Condition, select Simple.
    5. Click Add New Filter Condition, as shown in the following image:
    A message in the Filter Conditions table says there are no filter conditions specified. When you click the Add New Filter Condition icon, a row is created in the table for the new condition.
    When you click Add New Filter Condition, a new row is created where you specify values for the new filter condition.
    6. For Field Name, select State.
    7. For Operator, select Equals.
    8. To parameterize the filter condition value, for Value, select New Parameter.
    9. In the New Parameter dialog box, configure the following options:
    Filter Condition Detail
    Name of the filter condition.
    Enter p_FilterConditionValue for the name.
    Display Label
    Label that shows in the mapping task wizard where you enter the condition value.
    Enter Filter Value for State for the label.
    Description that appears in the mapping task wizard.
    Enter this text for the description: Enter the two-character state name for the data you want to use.
    Datatype of the field used for the filter condition.
    The State field is a String datatype, which is already specified in the dialog box.
    Default Value
    Default value for the filter condition. The mapping task uses this value unless you specify a different value.
    You want to run the task for accounts in Maryland by default, so enter MD.
    10. Click OK. The new filter condition displays in the Properties panel, as shown in the following image:
    The Filter Conditions table shows the completed filter condition.
    11. To save your changes, click Save.

Step 4. Configure a target

In the following procedure, you create a parameter for the target object so that each time you run the mapping task, you can select a different target.
For example, you might want files that only include data for the states you specify in the filter parameter when you run the mapping task. When you run the task, if you filter for accounts in California, you can select the file that contains data for California accounts as the target.
    1. On the mapping canvas, click the Target transformation to select it.
    2. To name the Target transformation, in the Properties panel, click General and enter tgt_Accounts_by_State for the Target transformation name.
    3. Click Target and configure the following properties:
    Target detail
    Connection to the target file.
    You want the target object to be a flat file and you want the target object to reside in the same location as the source file. You can use the same connection that you used for the source because the source is a flat file as well.
    Target Type
    Target object or parameter.
    You want to parameterize the target object so that you can have separate files for each state, so select Parameter.
    Parameter to use for the target object. This field only appears when you select Parameter as the target type.
    Click New Parameter, and for the parameter name, enter p_StateTargetParameter. For the display label, enter Accounts for State.
    Click OK.
    The following image shows the properties for the tgt_Accounts_by_State Target transformation:
    The Properties panel for tgt_Accounts_by_State shows the settings you made for the target connection, target type, and parameter.
    4. Click Field Mapping and for Field map options, select Automatic. You cannot specify field mappings because the target object is parameterized. Because you can select different target objects each time you run the task, the fields in the target objects might not be the same each time you run the task.
    5. Click Save. You now have a complete mapping.

Step 5. Validate and test the mapping

In the following procedure, you save and validate the mapping and then you test run the mapping.
You can save a mapping that is not valid. However, you cannot run a task that uses a mapping that is not valid. An example of an invalid mapping is a Source transformation or Target transformation that does not have a specified connection, or a mapping that does not have a Source transformation and a Target transformation.
    1. To validate the mapping, click Save.
    Whenever you save the mapping, the Mapping Designer validates the mapping. The status of the mapping displays in the header next to the mapping name. The mapping status can be Valid or Invalid.
    2. If the mapping is not valid, perform the following steps:
    1. a. In the header, click the Validation icon to open the Validation panel.
    2. The Validation panel lists the mapping and the transformations used in the mapping and shows where the errors occur. For example, in the following image, the tgt_Accounts_by_State Target transformation has an error:
      The Validation panel lists the mapping, Source transformation, Target transformation, and Filter transformation. An error icon displays next to the Target transformation.
    3. b. After you correct the errors, save the mapping and then in the Validation panel, click Refresh. The Validation panel updates to list any errors that might still be present.
    3. To test the mapping, click Run.
    The mapping canvas shows a complete mapping with the Source, Filter, and Target transformations. When the mapping is valid, you can click Run.
    4. In the wizard, select the runtime environment and click Next.
    In the first page of the wizard, you select the runtime environment to use to run the mapping. The wizard displays an image of the mapping.
    The Targets page appears. The Targets page appears because the target is parameterized. If you create a mapping that does not include a parameterized target, you will not see the Targets page when you run the mapping.
    The parameter you created for the target object displays on the page with the Accounts for State label, as you specified when you created the parameter.
    You can select a target object or create a new target object. For this tutorial, let's create a new target object that will include accounts for Texas.
    5. On the Targets page, click Create Target.
    The Target Parameters Details section of the Targets page includes the Accounts for State object parameter, where you can select a target object or create a new target. The Data Preview section of the Targets page displays data from the selected target object. Because we are creating a new target, no data appears.
    6. Enter the object name Accounts_By_State_TX and click OK.
    7. Click Next.
    The Input Parameters page appears. In the Filter Value for State text box, note that the default value you entered for the filter condition, MD, displays in the text box.
    8. Change the value from MD to TX so that the target file will include the accounts from Texas.
    9. Click Run.
    The mapping task runs and then returns you to the Mapping Designer.
    10. In the navigation bar, click My Jobs. The My Jobs page lists all of the jobs that you have run. At the top, you should see the mapping task that was created when you ran the mapping, as shown in the following diagram:
    The My Jobs page includes the asset name, date and time that the job completed, duration of the job, number of rows processed and status of the job.
    The My Jobs page shows that there were three accounts from Texas, which are now in your tgt_Accounts_By_State_TX target file.
    The AccountsByState .csv file lists three accounts that were filtered from the source file using the State value of TX.

Step 6. Create a mapping task

In the following procedure, you create a mapping task that uses the mapping that you just designed.
Now that you have a valid mapping, you can use the mapping task wizard to create tasks based on the mapping. Because you used parameters in the mapping, each time you run the task, you can change the parameter values. After the task runs, you have a target file that contains account information for the state that you specify in the filter condition parameter.
    1. To create a mapping task based on the mapping, while still in the Mapping Designer, click Actions and select New Mapping Task, as shown in the following image:
    The image shows the Actions menu, which includes New Mapping Task, Save, Run, Parameters Panel, and Validation Panel.
    The mapping task wizard appears.
    2. On the Definition page, enter mt_Accounts_by_State_task for the name of the task.
    3. Select the runtime environment to use to run this task. It should be the same runtime environment that you used to create and test the mapping.
    The following image shows the Definition page in the mapping task wizard:
    In the Definition page, you specify task details and select the runtime environment. You also specify the mapping to use for the task. The Definition page displays the mapping that you specify.
    4. Click Next.
    The Targets page appears. You can either select a target object from the list or click Create Target to create a new target.
    5. Click Next.
    The Input Parameters page appears and displays the Filter Value for State filter condition. You can change the value of the parameter, if desired.
    6. Click Next.
    The Schedule page appears. Because this is a tutorial and we do not want to run this mapping task on a regular basis, leave the default values.
    7. Click Finish to save the Accounts by State mapping task.