Professional Documents
Culture Documents
Expression Transformation
Expression Transformation
Expression
Transformation
This chapter includes the following topics:
♦ Overview, 142
♦ Creating an Expression Transformation, 143
141
Overview
Transformation type:
Passive
Connected
Use the Expression transformation to calculate values in a single row before you write to the
target. For example, you might need to adjust employee salaries, concatenate first and last
names, or convert strings to numbers. Use the Expression transformation to perform any non-
aggregate calculations. You can also use the Expression transformation to test conditional
statements before you output the results to target tables or other transformations.
Note: To perform calculations involving multiple rows, such as sums or averages, use the
Aggregator transformation. Unlike the Expression transformation, the Aggregator lets you
group and sort data. For more information, see “Aggregator Transformation” on page 37.
Calculating Values
To use the Expression transformation to calculate values for a single row, you must include the
following ports:
♦ Input or input/output ports for each value used in the calculation. For example, when
calculating the total price for an order, determined by multiplying the unit price by the
quantity ordered, the input or input/output ports. One port provides the unit price and
the other provides the quantity ordered.
♦ Output port for the expression. You enter the expression as a configuration option for the
output port. The return value for the output port needs to match the return value of the
expression. For more information about entering expressions, see “Working with
Expressions” on page 10. Expressions use the transformation language, which includes
SQL-like functions, to perform calculations.
1. In the Mapping Designer, click Transformation > Create. Select the Expression
transformation. Enter a name for it (the convention is EXP_TransformationName) and
click OK.
2. Create the input ports.
If you have the input transformation available, you can select Link Columns from the
Layout menu and then drag each port used in the calculation into the Expression
transformation. With this method, the Designer copies the port into the new
transformation and creates a connection between the two ports. Or, you can open the
transformation and create each port manually.
Note: If you want to make this transformation reusable, you must create each port
manually within the transformation.
3. Repeat the previous step for each input port you want to add to the expression.
4. Create the output ports (O) you need, making sure to assign a port datatype that matches
the expression return value. The naming convention for output ports is
OUT_PORTNAME.
5. Click the small button that appears in the Expression section of the dialog box and enter
the expression in the Expression Editor.
To prevent typographic errors, where possible, use the listed port names and functions.
If you select a port name that is not connected to the transformation, the Designer copies
the port into the new transformation and creates a connection between the two ports.
Port names used as part of an expression in an Expression transformation follow stricter
rules than port names in other types of transformations:
♦ A port name must begin with a single- or double-byte letter or single- or double-byte
underscore (_).
♦ It can contain any of the following single- or double-byte characters: a letter, number,
underscore (_), $, #, or @.
6. Check the expression syntax by clicking Validate.
If necessary, make corrections to the expression and check the syntax again. Then save the
expression and exit the Expression Editor.
7. Connect the output ports to the next transformation or target.
8. Select a tracing level on the Properties tab to determine the amount of transaction detail
reported in the session log file.
9. Click Repository > Save.