- Talend Open Studio Cookbook
- Rick Barton
- 865字
- 2025-03-31 04:04:57
Simple mapping and tMap time savers
This recipe will illustrate the most basic mapping options within the tMap
component and some of the column level tricks that can be used to speed up mapping by removing large amounts of repetitive actions.
Getting ready
Open the job jo_cook_ch04_0010_basicMapping.
How to do it...
- Drag a
tMap
component from the right-hand panel. - Connect the
tFileInputDelimited
component totMap
. - Connect the output, name it as
outputCustomer
and accept the schema of the target component. - Open
tMap
and you will notice that the inputs and outputs are named the same as the flows.Rename the flows
- Close
tMap
and left-click the input flow so that row1 is highlighted. Take a short pause; click again on therow1
text and the text will be editable. Rename the flow tocustomer
. - Open
tMap
and you will see that the names of thetMap
input table have now changed to match the row name of the input flow.Manually dragging columns
- Click the left mouse button on
dateOfBirth
and drag todateOfBirth
expression in the output. This is the most basic method of copying data from input to output.Create new columns by dragging
- Press Ctrl and left mouse click the
annualTotal
andprevYearTotal
columns. - Release Ctrl and left mouse click
annualTotal
. - Holding down the left mouse button, drag the columns to the very bottom of the output table.
- Do not release the left mouse button until you see a blue line at the end of the table and an information box that states Insert all selected entries.
- You will see that the new columns have been added to the output, and their values automatically mapped from the input.
Reposition a column
- Use the up and down arrows in the schema tab to move the new columns to the positions below
dateOfBirth
.Deleting a column
- Highlight
totalTwoYears
in the output table and then click the X button to delete it.Adding a column manually
- In the Schema editor for the output, left mouse click the
name
field, then click the + button to create a new column. - Change the name of
newColumn
topostcode
.Automapping same named columns
- Click the output table and then click Auto map!, as shown in the following screenshot:
- You should notice that all the columns that share the same input and output name have been mapped automatically.
Concatenating input columns
- Highlight the
firstName
,middleName
, andlastName
input columns by holding down Ctrl and left mouse clicking each one individually. - Drag them across to the output
name
column but do not release the left mouse button yet. While hovering over thename
column, notice the floating information box. This tells us that the mode is append. - Release the left mouse button and notice that the three columns have been copied to the same expression.
- Repeat steps 10 to 12, and you will see that the columns have been appended yet again. Append is the default mode when dragging and dropping.
Overwriting columns
- Repeat steps 10 to 12, however before releasing the left mouse button hold down Ctrl. You will see that the information box changes to Overwrite mode.
- Release the left mouse button, and you will see that the expression containing six fields has been overwritten by three.
- Add
+"
"+
between each of the columns to complete the expression.Copy columns by position
- Highlight the
payment1
column. - Hold the Shift key and click
payment4
. - Release the left mouse button, select the
payment1
column and drag the group across to thelastFourPayments1
column in the output. - Drag the four columns to the output, but do not release the mouse button. Notice that the floating box says that this is the append mode.
- Press Ctrl and you will see that the mode changes to overwrite mode
- Press Shift and the mode changes to each source entry to each target expression.
- This is the mode we want, so release the left mouse button. You will see that the columns have been mapped individually. Note that the copy of multiple columns by position can also be performed with non-sequential columns selected using Ctrl and left mouse click.
- Your
tMap
should now look like the following and you can run the job.
How it works...
tMap
enables columns to be mapped, ignored, and added to the output very easily to ensure that the correct results are produced.
Shortcuts such as Auto map! and the group copies, enable many rows to be copied at once, saving time and effort.
New columns can be created by dragging and dropping from the input, as well as via the schema editor.
There's more…
In this recipe there is just a single input and output, so recognizing the source column in an expression is simple. When multiple inputs and outputs are used, then this is no longer true, unless flows are named sensibly. This is why we have included the renaming of the flows in this, the most basic recipe.