Filter Paths
Keep only paths that satisfy a metric condition.
The condition is a tree of comparison nodes connected by and / or / not
branch nodes. Per-path metrics are computed once and the condition is evaluated
in SQL.
Raises EmptyEventstreamError when no paths match.
Usage
# Keep paths that contain at least one purchase
stream.filter_paths({"op": ">", "metric": "event_count", "value": 0, "metric_args": {"events": "purchase"}})
# Keep paths longer than 3 events that match a funnel pattern
# (a top-level list means AND)
stream.filter_paths([
{"op": ">", "metric": "length", "value": 3},
{"op": "=", "metric": "matches_pattern", "value": True,
"metric_args": {"pattern": "registration->.*->purchase"}},
])
Parameters
| Parameter | Type | Description |
|---|---|---|
condition | dict or list | Condition tree. Leaf nodes have the keys: Branch nodes have op set to and, or, or not and an args list of child nodes. A plain list of nodes is shorthand for AND: [cond1, cond2] ≡ {"op": "and", "args": [cond1, cond2]}. |
path_col | str, optional | Path ID column override; defaults to schema.path_col. |
event_col | str, optional | Event column override; defaults to schema.event_col. |
Leaf node keys
op— comparison operator:>,>=,<,<=,=(or==),!=.metric— metric name (see the Path Metrics documentation page for the full list).value— threshold value.metric_args(optional) — dict of extra arguments for the metric.