Developer Transformation Guide > Introduction to Transformations > Expressions in Transformations
  

Expressions in Transformations

You can enter expressions in the Expression Editor in some transformations. Expressions modify data or test whether data matches conditions.
Create expressions that use transformation language functions. Transformation language functions are SQL-like functions that transform data.
Enter an expression in a port that uses the value of data from an input or input/output port. For example, you have a transformation with an input port IN_SALARY that contains the salaries of all the employees. You might use the values from the IN_SALARY column later in the mapping. You might also use the transformation to calculate the total and average salaries. The Developer tool requires you to create a separate output port for each calculated value.
The following table lists the transformations in which you can enter expressions:
Transformation
Expression
Return Value
Aggregator
Performs an aggregate calculation based on all data passed through the transformation. Alternatively, you can specify a filter for records in the aggregate calculation to exclude certain kinds of records. For example, you can find the total number and average salary of all employees in a branch office using this transformation.
Result of an aggregate calculation for a port.
Expression
Performs a calculation based on values within a single row. For example, based on the price and quantity of a particular item, you can calculate the total purchase price for that line item in an order.
Result of a row-level calculation for a port.
Filter
Specifies a condition used to filter rows passed through this transformation. For example, if you want to write customer data to the BAD_DEBT table for customers with outstanding balances, you could use the Filter transformation to filter customer data.
TRUE or FALSE, based on whether a row meets the specified condition. The Data Integration Service passes rows that return TRUE through this transformation. The transformation applies this value to each row that passes through it.
Joiner
Specifies an advanced condition used to join unsorted source data. For example, you can concatenate first name and last name master ports and then match them with the full name detail port.
TRUE or FALSE, based on whether the row meets the specified condition. Depending on the type of join selected, the Data Integration Service either adds the row to the result set or discards the row.
Rank
Sets the conditions for rows included in a rank. For example, you can rank the top 10 salespeople who are employed with the organization.
Result of a condition or calculation for a port.
Router
Routes data into multiple transformations based on a group expression. For example, use this transformation to compare the salaries of employees at three different pay levels. You can do this by creating three groups in the Router transformation. For example, create one group expression for each salary range.
TRUE or FALSE, based on whether a row meets the specified group expression. The Data Integration Service passes rows that return TRUE through each user-defined group in this transformation. Rows that return FALSE pass through the default group.
Update Strategy
Flags a row for update, insert, delete, or reject. You use this transformation when you want to control updates to a target, based on some condition you apply. For example, you might use the Update Strategy transformation to flag all customer rows for update when the mailing address has changed. Or, you might flag all employee rows for reject for people who no longer work for the organization.
Numeric code for update, insert, delete, or reject. The transformation applies this value to each row passed through it.

The Expression Editor

Use the Expression Editor to build SQL-like statements.
You can enter an expression manually or use the point-and-click method. Select functions, ports, variables, and operators from the point-and-click interface to minimize errors when you build expressions. The maximum number of characters you can include in an expression is 32,767.

Port Names in an Expression

You can enter transformation port names in an expression.
For connected transformations, if you use port names in an expression, the Developer tool updates that expression when you change port names in the transformation. For example, you write an expression that determines the difference between two dates, Date_Promised and Date_Delivered. If you change the Date_Promised port name to Due_Date, the Developer tool changes the Date_Promised port name to Due_Date in the expression.

Adding an Expression to a Port

You can add an expression to an output port.
    1. In the transformation, select the port and open the Expression Editor.
    2. Enter the expression. Use the Functions and Ports tabs and the operator keys.
    Note: You cannot use an escape character in an expression. If you include an escape character in the expression, the Developer tool might display a parse error.
    3. Optionally, add comments to the expression.
    Use comment indicators -- or //.
    4. Click the Validate button to validate the expression.
    5. Click OK.
    6. If the expression is not valid, fix the validation errors and validate the expression again.
    7. When the expression is valid, click OK to close the Expression Editor.

Comments in an Expression

You can add comments to an expression to describe the expression or to specify a valid URL to access business documentation about the expression.
To add comments within the expression, use -- or // comment indicators.

Expression Validation

You need to validate an expression to run a mapping or preview mapplet output.
Use the Validate button in the Expression Editor to validate an expression. If you do not validate an expression, the Developer tool validates it when you close the Expression Editor. If the expression is invalid, the Developer tool displays a warning. You can save the invalid expression or modify it.

Test Expressions

You can test some expressions that you configure in the Expression Editor. When you test an expression, you enter sample data and then evaluate the expression.
You can test expressions when you configure expressions in the following ways:
For example, after configuring an expression that concatenates the first name, a space, and the last name, you can enter sample data for the ports, and then evaluate the expression to verify the result.
The following image shows the results of an expression that concatenates a sample first name and last name:
In the testing panel, "John" is the test value for the FirstName field and "Baer" is the test value for the LastName field. The result of the expression is "John Baer."

Date Format Strings for Sample Data

When you test an expression that uses a port with the Date/Time or Timestamp with Time Zone data type, you must enter sample data for the port using the required date format string.
To enter sample data for a port with the Date/Time data type, use the format MM/DD/YYYY HH24:MI:SS. When you evaluate the expression, the Expression Editor displays the result using the format that you specify in the expression. If you omit the format string in the expression, the Expression Editor displays the result using the same format MM/DD/YYYY HH24:MI:SS.
To enter sample data for a port with the Timestamp with Time Zone data type, use the format MM/DD/YYYY HH24:MI:SS TZR. When you evaluate the expression, the Expression Editor displays the result using the format YYYY-MM-DD HH24:MI:SS.NS TZR.

Data Type Conversion

Multiple expression and aggregation functions might generate data of a data type that is different from the input data.
For example, when you multiply two decimal numbers with a precision of 18 digits, the resulting data type could be a decimal with a precision of 28 digits.
For input data type of Decimal with a precision of 38 digits, the result of certain operations might produce data that may not fit into resultant data type. So the user might get an overflow exception.
The following functions might require a data type conversion to accommodate an increase in the size of the data when compared to the input data types:
For example, when the input data is of the Integer data type and you use multiplication operation, the resulting data type could be of the bigint data type. Similarly, when the input data type is of the Decimal data type of precision as 18 digits, the result of the multiplication operation might be large and within Decimal data type of the precision as 28 digits.