In this article
The Filter Snap filters a document stream based on an expression. If the filter expression evaluates to true, then the document will be passed-through. If the filter expression evaluates to false, then the document will be dropped in the stream. Expressions that do not evaluate to a boolean value will cause the pipeline to fail. Learn more about Expression functions.
|
The Filter Snap is a Flow-type Snap.
Works in Ultra Pipelines.
When using the Filter Snap in an ultra pipeline, the pipeline returns an empty response if the Snap filters the incoming document. |
Type | Format | Number of Views | Examples of Upstream and Downstream Snaps | Description |
---|---|---|---|---|
Input | Document | Min: 1 Max: 1 | JSON Generator | The data in the input document to filter. |
Output | Document | Min: 1 Max: 1 |
| The filtered document. |
Error | Error handling is a generic way to handle errors without losing data or failing the Snap execution. You can handle the errors that the Snap might encounter when running the pipeline by choosing one of the following options from the When errors occur list under the Views tab:
Learn more about Error handling in Pipelines. |
|
Field | Field Type | Description | |
---|---|---|---|
Label*
| String | The name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your pipeline. | |
Null-safe access
| Checkbox | Select this checkbox to consider the missing data or empty value as null when accessing the source path. If you deselect this checkbox, the Snap fails and displays error in case there is missing data or empty value when accessing the source path. | |
Filter Expression* $first_name == "Joe" startsWith($description, "Snap") && $quantity < 100 | String/Expression | The expression to evaluate. If this expression evaluates to true, then the document will be passed through. Otherwise, the document will be dropped. If the expression does not evaluate to a boolean, then the pipeline will fail. | |
Snap Execution Default Value: Validate & Execute | Dropdown list | Select one of the three modes in which the Snap executes. Available options are:
|
This example pipeline demonstrates how to filter data with missing data or empty values using the Null-safe access checkbox.
Configure the JSON Generator Snap with the following data. Each record has location and salary except ID102,
which does not have the location.
Configure the Filter expression as $location=="Hyderabad" || $salary>=20000 which means the Snap should filter and display the records in the output that has the location as Hyderabad OR the salary at least INR 20000. Select the Null-safe access checkbox—the Snap then finds any missing data while accessing the source path ( such as record#102, which does not have a location); the Snap considers the field null, a valid filter criteria.
Validate the pipeline, the Filter Snap returns the output as follows: