• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
 
141
C h a p t e r 5
ExpressionTransformation
This chapter includes the following topics:
Overview, 142
Creating an Expression Transformation, 143
 
142Chapter 5: Expression Transformation
Overview
Use the Expression transformation to calculate values in a single row before you write to thetarget. For example, you might need to adjust employee salaries, concatenate first and lastnames, or convert strings to numbers. Use the Expression transformation to perform any non-aggregate calculations. You can also use the Expression transformation to test conditionalstatements 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 yougroup 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 thefollowing ports:
Input or input/output ports for each value used in the calculation.
For example, whencalculating the total price for an order, determined by multiplying the unit price by thequantity ordered, the input or input/output ports. One port provides the unit price andthe other provides the quantity ordered.
Output port for the expression.
 You enter the expression as a configuration option for theoutput port. The return value for the output port needs to match the return value of theexpression. For more information about entering expressions, see “Working withExpressions” on page 10. Expressions use the transformation language, which includesSQL-like functions, to perform calculations.
 Adding Multiple Calculations
 You can enter multiple expressions in a single Expression transformation. As long as you enteronly one expression for each output port, you can create any number of output ports in thetransformation. In this way, use one Expression transformation rather than creating separatetransformations for each calculation that requires the same set of data.For example, you might want to calculate several types of withholding taxes from eachemployee paycheck, such as local and federal income tax, Social Security and Medicare. Sinceall of these calculations require the employee salary, the withholding category, and/or thecorresponding tax rate, you can create one Expression transformation with the salary and withholding category as input/output ports and a separate output port for each necessary calculation.
Transformation type:
PassiveConnected
 
Creating an Expression Transformation 143
Creating an Expression Transformation
Use the following procedure to create an Expression transformation.
To create an Expression transformation:1.
In the Mapping Designer, click Transformation > Create. Select the Expressiontransformation. Enter a name for it (the convention is EXP_
TransformationName 
) andclick OK.
2.
Create the input ports.If you have the input transformation available, you can select Link Columns from theLayout menu and then drag each port used in the calculation into the Expressiontransformation. With this method, the Designer copies the port into the new transformation and creates a connection between the two ports. Or, you can open thetransformation and create each port manually.
Note:
If you want to make this transformation reusable, you
 
must create each portmanually 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 matchesthe expression return value. The naming convention for output ports isOUT_
PORTNAME 
.
5.
Click the small button that appears in the Expression section of the dialog box and enterthe 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 copiesthe 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 stricterrules than port names in other types of transformations:
 A port name must begin with a single- or double-byte letter or single- or double-byteunderscore (_).
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 theexpression 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 detailreported in the session log file.
9.
Click Repository > Save.
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...