Skip to content

Filterif

flowtask.components.FilterIf

FilterIf

FilterIf(loop=None, job=None, stat=None, **kwargs)

Bases: FlowComponent

FilterIf.

Overview

    The FilterIf is a component that applies specified filters to a Pandas DataFrame.
    if the condition is met, the row is kept, otherwise it is discarded.
    at result set (if any) will be executed a subset of components.

.. table:: Properties
:widths: auto

    +--------------+----------+-----------+---------------------------------------------------------------+
    | Name         | Required | Summary                                                                   |
    +--------------+----------+-----------+---------------------------------------------------------------+
    | operator     |   Yes    | Logical operator (e.g., `and`, `or`) used to combine filter conditions.   |
    +--------------+----------+-----------+---------------------------------------------------------------+
    | conditions   |   Yes    | List of conditions with columns, values, and expressions for filtering.   |
    |              |          | Format: `{ "column": <col_name>, "value": <val>, "expression": <expr> }`  |
    +--------------+----------+-----------+---------------------------------------------------------------+
    | filter       |   Yes    | List of conditions with columns, values, and expressions for filtering.   |
    |              |          | Format: `{ "column": <col_name>, "value": <val>, "expression": <expr> }`  |
    +--------------+----------+-----------+---------------------------------------------------------------+
    | true_condition|  Yes    | List of components to execute if the condition is met.                   |
    +--------------+----------+-----------+---------------------------------------------------------------+
    | false_condition| Yes    | List of components to execute if the condition is not met.               |
    +--------------+----------+-----------+---------------------------------------------------------------+
    | passthrough |   No     | If True, the component will pass through the data without filtering.      |
    +--------------+----------+-----------+---------------------------------------------------------------+
Returns

    This component returns a filtered Pandas DataFrame based on the provided conditions.
    The component tracks metrics such as the initial and filtered row counts,
    and optionally limits the returned columns if specified.
    Additional debugging information can be outputted based on configuration.

Example:
- FilterIf:
    operator: "&"
    filter:
        - column: previous_form_id
        expression: not_null
    true_condition:
        - TransformRows:
            replace_columns: true
            fields:
            form_id: previous_form_id
        - ExecuteSQL:
            file_sql: delete_previous_form.sql
            use_template: true
            use_dataframe: true