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": {"event": "purchase"}})

# Keep paths that contain a promo_view or a discount_applied event
stream.filter_paths({"op": "=", "metric": "has_any_event", "value": True,
                      "metric_args": {"events": ["promo_view", "discount_applied"]}})

# 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

ParameterTypeDescription
conditiondict or listCondition 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]}. has_event/event_count take a single event (string) — for a multi-event AND/OR condition use has_all_events/has_any_event with an events list instead. has_event_bulk/event_count_bulk (which expand into one column per event, for segment_overview/add_clusters) cannot be used here since a condition needs exactly one value per path.
path_colstr, optionalPath ID column override; defaults to schema.path_col.
event_colstr, optionalEvent 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.