You are on page 1of 16

Expression Transformation

Expression Transformation in Informatica, is a connected passive transformation (number of input and


output rows is the same), which lets you modify individual ports of a single row, or add or suppress
them. It helps implement the complicated data transforms, applies business logic and performs checks
and validations. For example: calculating annual Salary, concatenation etc. We will go through the
properties of Expression Transformation. We will also discuss the steps of adding /configuring
expression transformation in Informatica Mapping. We will also check some performance tuning related
guidelines of Expression Transformation.

Business Purpose:
The Expression transformation is use to perform non-aggregate calculations for each data. Data can be
modified using logical and numeric operators or built-in functions. Sample transformations handled by
the expression transformer are:

Data Manipulation

: concatenation( CONCAT or || ) , Case change (UPPER,LOWER)

truncation, InitCap (INITCAP)

Datatype conversion : (TO_DECIMAL, TO_CHAR, TO_DATE)

Data cleansing - check nulls (ISNULL) , replace chars, test for spaces (REPLACESTR) , test for
number

Manipulate dates convert, add, test (GET_DATE_PART, IS_DATE, DIFF_DATES)

Scientific calculations and numerical operations exponential, power, log, modulus (LOG,
POWER, SQRT)

ETL specific - if, lookup, decode (IIF, DECODE)

Properties of Expression Transformation:

Expression Transformation is a Passive transformation as it only modifies the incoming port


data, but it doesnt affect the number of rows processed.
Expression Transformation is a connected Transformation

Types of ports in Expression Transformation:


Input
Output
Variable: Used to store any temporary calculation

How to use Expression transformation in Informatica:


Use the following procedure to create an Expression transformation.

Steps to create an Expression transformation:


1. In the Mapping Designer, open a mapping.
2. Click Transformation > Create. Select Expression transformation.
3. You can also select Transformation by clicking function button on Informatica Designer
4. Enter a name and click Done.
5. Select and drag the ports from the source qualifier or other transformations to add to the Expression
transformation. You can also open the transformation and create ports manually.
6. Double-click on the title bar and click on Ports tab. You can create output and variable ports within the
transformation.
7. In the Expression section of an output or variable port, open the Expression Editor.
8. Enter an expression. Click Validate to verify the expression syntax.
9. Click OK.
10. Assign the port datatype, precision, and scale to match the expression return value.
11. To make it reusable, check the reusable option in the edit properties.
12. Configure the tracing level on the Properties tab.
13. Click OK.
14. Connect the output ports to a downstream transformation or target.
Note: After you make the transformation reusable, you cannot copy ports from the source qualifier or
other transformations. You can create ports manually within the transformation.

Expression Transformation Performance Tuning:

Try to use numeric operation instead of string one

Use of operators is faster than functions (i.e. || vs. CONCAT).

Use transformation variables to break down complex transformation logic into smaller parts. You can
define variable port by clicking on V check box while defining the port. In the expression editor of it , it
can all input port and other variable port for calculation

It is highly recommended to define a naming convention for the input and output ports for expressions.
For example, all input ports have an in_ prefix for Input port , out_ for output ports and var_ for
variables port:

Ports are evaluated in the following order: input ports first, then variable ports in the display order
(from top to bottom), then output ports.

Example of Expression Transformation


Problem Statement:
Create a mapping to populate Target table with first name and last name concatenated. It should also
populate the total annual Salary considering the commission as well.

Solution:
Step 1:
Create a new Target table in the target table by the name of Employee_salary
Create Table TARGET.EMPLOYEES_SALARY (
EMPLOYEE_ID DECIMAL(6,0),
FULL_NAME VARCHAR(50),
JOB_ID VARCHAR(10),
SALARY DECIMAL(8,2),
COMMISSION_PCT DECIMAL(2,2),
TOTAL_SALARY DECIMAL(12,2));

Step 2:

Create a new mapping named m_Employees_Employees_Salary by Go to toolbar -> click


mapping->
Drag Source (Employees) and Target (Employees_Salary) to the mapping.
Add Expression Transformation by Go to Toolbar->click Transformation -> Create. Select the
Expression transformation

Give a name Enter a name like exp_Salary, click on Create and then click on Done.
Drag all required port (EMPLOYEE_ID, FIRST_NAME, LAST_NAME, JOB_ID, SALARY,
COMMISSION_PCT) from Source Qualifier to expression transformation

Double click exp_Salary Expression to edit it


Create two output port (FULL_NAME, TOTAL_SALARY) and one variable port
v_annual_Salary.

Click on expression button for the FULL_NAME and add expression to concatenate
FIRST_NAME and LAST_NAME as FIRST_NAME|| ||LAST_NAME. You can use
Concatenate operator from Operator Keypad as show in below figure.

Click on validate button to validate the expression

Similarly edit the expression for v_annual_sal = SALARY * 12

Similarly edit the Total_Salary port with expression as v_anual_salary + (v_anual_salary


* (IIF(ISNULL(COMMISSION_PCT),0,COMMISSION_PCT)))Here in case of NULL
commission we are adding 0.

Now join the output port of exp_salary to EMPLOYEES_SALARY.

Click on Mapping ( from tool bar) -> then Validate ( to validate the mapping)

Now save the mapping ( by clicking on Repository-> Save or you can also press
Ctrl+S)

Generate the workflow and run it

Over all Mapping:

How to use Informatica Help for more functions

While your in the Informatica designers expression transformation, click on any function and
you can see the details of it in the information section as below:

You can get more information on any specific function by clicking on the Help button and then
typing the functions name in the search bar:

Using the IIF Function in the Expression Transformation


Returns one of two values you specify, based on the results of a condition.

Syntax
IIF( condition, value1 [,value2] )
The following table describes the arguments for this command:
Argument
Required/ Description
Optional
condition
Required
The condition you want to evaluate. You can enter any valid
transformation expression that evaluates to TRUE or FALSE.
value1
Required
Any datatype except Binary. The value you want to return if the condition
is TRUE. The return value is always the datatype specified by this
argument. You can enter any valid transformation expression, including
another IIF expression.
value2
Optional
Any datatype except Binary. The value you want to return if the condition
is FALSE. You can enter any valid transformation expression, including
another IIF expression.
Unlike conditional functions in some systems, the FALSE (value2) condition in the IIF function is not
required. If you omit value2, the function returns the following when the condition is FALSE:

0 if value1 is a Numeric datatype.


Empty string if value1 is a String datatype.
NULL if value1 is a Date/Time datatype.
You can often use a Filter transformation instead of IIF to maximize session performance.

Example of IIF Function:


Problem Statement: Load the salaries of employees in a table and flag them as High, Medium or
Low based on the following business rules:
SALARY_STATUS
LOW
MEDIUM
HIGH

CONDITION
SALARY < 5000
SALARY >= 5000 && SALARY<10000
SALARY >= 10000

Solution
Step 1:
Create a new table in the TARGET database with the following definition:

Create Table TARGET.EMPLOYEES_SALARY_STATUS (


EMPLOYEE_ID DECIMAL(6,0),
FIRST_NAME VARCHAR(20),
LAST_NAME VARCHAR(25),
SALARY DECIMAL(8,2),
SALARY_STATUS VARCHAR(10));
Step 2:

Create a mapping using the Source: HR.EMPLOYEE, Transformation: EXPRESSION, Target:


TARGET.EMPLOYEES_SALARY_STATUS:

Create one new output port in the expression transformation o_SALARY_STATUS and enter the
following expression in it: IIF(SALARY < 5000 , LOW , IIF(SALARY >= 5000 AND SALARY < 10000
, MEDIUM , HIGH))

Generate the workflow and run it.

Using the ERROR Function in the Expression Transformation


Causes the PowerCenter Integration Service to skip a row and issue an error message, which you define.
The error message displays in the session log. The PowerCenter Integration Service does not write these
skipped rows to the session reject file.
Use ERROR in Expression transformations to validate data. Generally, you use ERROR within an IIF or
DECODE function to set rules for skipping rows.
Use the ERROR function for both input and output port default values. You might use ERROR for input
ports to keep null values from passing into a transformation.
Use ERROR for output ports to handle any kind of transformation error, including ERROR function calls
within an expression. When you use the ERROR function in an expression and in the output port default
value, the PowerCenter Integration Service skips the row and logs both the error message from the
expression and the error message from the default value. If you want to ensure the PowerCenter
Integration Service skips rows that produce an error, assign ERROR as the default value.
If you use an output default value other than ERROR, the default value overrides the ERROR function in
an expression. For example, you use the ERROR function in an expression, and you assign the default
value, 1234, to the output port. Each time the PowerCenter Integration Service encounters the ERROR
function in the expression, it overrides the error with the value 1234 and passes 1234 to the next
transformation. It does not skip the row, and it does not log an error in the session log.

Syntax
ERROR( string )
The following table describes the argument for this command:
Argument
string

Required/
Optional
Required

Description
String value. The message you want to display when the Integration
Service skips a row based on the expression containing the ERROR
function. The string can be any length.

Return Value
String.

Example of ERROR Function:


Problem Statement: Send the incoming negative salaries to the .bad file and load the rest to
the target table.
Solution:
Step 1:
Create a new table in the TARGET database with the following definition:

Create Table TARGET.EMPLOYEES_SALARY_STATUS (


EMPLOYEE_ID DECIMAL(6,0),

FIRST_NAME VARCHAR(20),
LAST_NAME VARCHAR(25),
SALARY DECIMAL(8,2),
SALARY_STATUS VARCHAR(10));
Step 2:

Create a mapping using the Source: HR.EMPLOYEE, Transformation: EXPRESSION, Target:


TARGET.EMPLOYEES_SALARY_STATUS:

Create another output port named o_SALARY_OUT and specify the following expression in it
IIF(SALARY<0 , ERROR(Negative Salary), SALARY):

Generate the workflow and run it.

Using the ABORT Function in the Expression Transformation


Stops the session, and issues a specified error message to the session log file. When the PowerCenter
Integration Service encounters an ABORT function, it stops transforming data at that row. It processes
any rows read before the session aborts and loads them based on the source- or target-based commit
interval and the buffer block size defined for the session. The PowerCenter Integration Service writes to
the target up to the aborted row and then rolls back all uncommitted data to the last commit point. You
can perform recovery on the session after rollback.
Use ABORT to validate data. Generally, you use ABORT within an IIF or DECODE function to set rules for
aborting a session.
Use the ABORT function for both input and output port default values. You might use ABORT for input
ports to keep null values from passing into a transformation. You can also use ABORT to handle any kind
of transformation error, including ERROR function calls within an expression. The default value overrides
the ERROR function in an expression. If you want to ensure the session stops when an error occurs,
assign ABORT as the default value.
If you use ABORT in an expression for an unconnected port, the PowerCenter Integration Service does
not run the ABORT function.
Note: The PowerCenter Integration Service handles the ABORT function and the Abort command you
issue from the Workflow Manager differently.
Syntax
ABORT( string )
The following table describes the argument for this command:
Argument Required/ Description
Optional
string
Required String. The message you want to display in the session log file when the
session stops. The string can be any length. You can enter any valid
transformation expression.
Return Value
NULL.

Example of ABORT Function:


Problem Statement: Reject the incoming negative salaries and fail the complete session.
Solution:
Step 1:
Create a new table in the TARGET database with the following definition:

Create Table TARGET.EMPLOYEES_SALARY_STATUS (


EMPLOYEE_ID DECIMAL(6,0),
FIRST_NAME VARCHAR(20),
LAST_NAME VARCHAR(25),
SALARY DECIMAL(8,2),
SALARY_STATUS VARCHAR(10));

Step 2:

Create a mapping using the Source: HR.EMPLOYEE, Transformation: EXPRESSION, Target:


TARGET.EMPLOYEES_SALARY_STATUS:

Create another output port named o_SALARY_OUT and specify the following
expression in it IIF(SALARY<0 , ABORT(Negative Salary), SALARY):

Generate the workflow and run it.

Difference between ERROR and ABORT


Error function causes the PowerCenter Integration Service to skip a row and issue an error message,
which you define. The error message displays in the session log. The PowerCenter Integration Service
does not write these skipped rows to the session reject file.
Use ERROR in Expression transformations to validate data. Generally, you use ERROR within an IIF or
DECODE function to set rules for skipping rows.
Use the ERROR function for both input and output port default values. You might use ERROR for input
ports to keep null values from passing into a transformation.
Use ERROR for output ports to handle any kind of transformation error, including ERROR function calls
within an expression. When you use the ERROR function in an expression and in the output port default
value, the PowerCenter Integration Service skips the row and logs both the error message from the
expression and the error message from the default value. If you want to ensure the PowerCenter
Integration Service skips rows that produce an error, assign ERROR as the default value.
Abort Stops the session, and issues a specified error message to the session log file. When the
PowerCenter Integration Service encounters an ABORT function, it stops transforming data at that row.
It processes any rows read before the session aborts and loads them based on the source- or targetbased commit interval and the buffer block size defined for the session. The PowerCenter Integration
Service writes to the target up to the aborted row and then rolls back all uncommitted data to the last
commit point. You can perform recovery on the session after rollback.
Use ABORT to validate data. Generally, you use ABORT within an IIF or DECODE function to set rules for
aborting a session.
Use the ABORT function for both input and output port default values. You might use ABORT for input
ports to keep null values from passing into a transformation. You can also use ABORT to handle any kind
of transformation error, including ERROR function calls within an expression. The default value overrides
the ERROR function in an expression. If you want to ensure the session stops when an error occurs,
assign ABORT as the default value.

You might also like