Filter
The Filter processor passes records that match the filter condition to downstream stages. Records that do not match the filter condition are removed from the pipeline.
Use the Filter processor to remove unwanted records from the pipeline. To route data to separate downstream branches based on different conditions, use the Stream Selector processor.
When you configure the Filter processor, you specify the filter condition to use.
Filter Condition
The filter condition determines the data that passes downstream. The filter condition must evaluate to true or false. Records that evaluate to true pass to the rest of the pipeline.
You can use a condition as simple as AccountID is NOT NULL
or you can
create as complex a condition as needed.
- When you define a condition, you typically base it on field values in the record. For information about referencing fields in the condition, see Referencing Fields in Spark SQL Expressions.
- You can use any Spark SQL
syntax that can be used in the WHERE clause of a query, including functions such as
isnull
ortrim
and operators such as=
or<=
.You can also use user-defined functions (UDFs), but you must define the UDFs in the pipeline. Use a pipeline preprocessing script to define UDFs.
For more information about Spark SQL functions, see the Apache Spark SQL Functions documentation.
year(transaction_date) >= 2000
Sample Conditions
The following table lists some common scenarios that you might adapt for your use:Condition Example | Description |
---|---|
total > 0 |
If the value in the total field is greater
than 0, the record passes downstream. If not, the record is
dropped from the pipeline. |
total <= 0 |
If the value in the total field is less than
or equal to 0, the record passes downstream. If not, the record
is dropped from the pipeline. |
accountId is NOT NULL |
If the record has a value in the accountId
field, the record passes downstream. If the field contains a
null value, the record is dropped from the pipeline.Note that
|
upper(message) like '%ERROR%' |
If the message field contains the string,
ERROR , the record passes downstream. If
not, the record is dropped from the pipeline.The condition
changes the strings in the |
initcap(country) like 'China' OR initcap(country)
like 'Japan' |
If the value in the country field is
China or Japan , the record
passes downstream. If not, the record is dropped from the
pipeline.The condition changes the strings in the
|
Configuring a Filter Processor
-
In the Properties panel, on the
General tab, configure the following properties:
General Property Description Name Stage name. Description Optional description. Cache Data Caches data processed for a batch so the data can be reused for multiple downstream stages. Use to improve performance when the stage passes data to multiple stages. Caching can limit pushdown optimization when the pipeline runs in ludicrous mode.
- On the Filter tab, specify the filter condition to use.