Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Filter Transformation
189
Overview
Transformation type:
Active
Connected
You can filter rows in a mapping with the Filter transformation. You pass all the rows from a
source transformation through the Filter transformation, and then enter a filter condition for
the transformation. All ports in a Filter transformation are input/output, and only rows that
meet the condition pass through the Filter transformation.
In some cases, you need to filter data based on one or more conditions before writing it to
targets. For example, if you have a human resources target containing information about
current employees, you might want to filter out employees who are part-time and hourly.
The mapping in Figure 7-1 passes the rows from a human resources table that contains
employee data through a Filter transformation. The filter only allows rows through for
employees that make salaries of $30,000 or higher.
With the filter of SALARY > 30000, only rows of data where employees that make salaries
greater than $30,000 pass through to the target.
As an active transformation, the Filter transformation may change the number of rows passed
through it. A filter condition returns TRUE or FALSE for each row that passes through the
transformation, depending on whether a row meets the specified condition. Only rows that
return TRUE pass through this transformation. Discarded rows do not appear in the session
log or reject files.
To maximize session performance, include the Filter transformation as close to the sources in
the mapping as possible. Rather than passing rows you plan to discard through the mapping,
you then filter out unwanted data early in the flow of data from sources to targets.
You cannot concatenate ports from more than one transformation into the Filter
transformation. The input ports for the filter must come from a single transformation. The
Filter transformation does not allow setting output default values.
Overview 191
Filter Condition
You use the transformation language to enter the filter condition. The condition is an
expression that returns TRUE or FALSE. For example, if you want to filter out rows for
employees whose salary is less than $30,000, you enter the following condition:
SALARY > 30000
You can specify multiple components of the condition, using the AND and OR logical
operators. If you want to filter out employees who make less than $30,000 and more than
$100,000, you enter the following condition:
SALARY > 30000 AND SALARY < 100000
You do not need to specify TRUE or FALSE as values in the expression. TRUE and FALSE
are implicit return values from any condition you set. If the filter condition evaluates to
NULL, the row is assumed to be FALSE.
Enter conditions using the Expression Editor, available from the Properties tab of the Filter
transformation. The filter condition is case sensitive. Any expression that returns a single
value can be used as a filter. You can also enter a constant for the filter condition. The
numeric equivalent of FALSE is zero (0). Any non-zero value is the equivalent of TRUE. For
example, if you have a port called NUMBER_OF_UNITS with a numeric datatype, a filter
condition of NUMBER_OF_UNITS returns FALSE if the value of NUMBER_OF_UNITS
equals zero. Otherwise, the condition returns TRUE.
After entering the expression, you can validate it by clicking the Validate button in the
Expression Editor. When you enter an expression, validate it before continuing to avoid
saving an invalid mapping to the repository. If a mapping contains syntax errors in an
expression, you cannot run any session that uses the mapping until you correct the error.
Open Button
6. Click the Value section of the condition, and then click the Open button.
The Expression Editor appears.
Tips 195
Troubleshooting
I imported a flat file into another database (Microsoft Access) and used SQL filter queries to
determine the number of rows to import into the Designer. But when I import the flat file into
the Designer and pass data through a Filter transformation using equivalent SQL
statements, I do not import as many rows. Why is there a difference?
You might want to check two possible solutions:
♦ Case sensitivity. The filter condition is case sensitive, and queries in some databases do not
take this into account.
♦ Appended spaces. If a field contains additional spaces, the filter condition needs to check
for additional spaces for the length of the field. Use the RTRIM function to remove
additional spaces.
This condition states that if the FIRST_NAME port is NULL, the return value is FALSE and
the row should be discarded. Otherwise, the row passes through to the next transformation.
For more information about the ISNULL and IS_SPACES functions, see “Functions” in the
Transformation Language Reference.