|
| 1 | +DESCRIPTION > |
| 2 | + - `activities_daily_counts.pipe` returns **daily unique activity counts** for one or more segments. |
| 3 | + - Uses `uniqExact(activityId)` by default (exact); |
| 4 | + - Designed for short windows (e.g., ≤30 days). With ~1–2k records/day, exact distinct is typically fast enough. |
| 5 | + - Supported filters: required segments, optional time range (`after`/`before`), and optional `platform`. |
| 6 | + - Parameters: |
| 7 | + - `segmentIds` (**required**): Array of Strings (e.g., `['xx-xxx-xxx-xx-xxxx']`). |
| 8 | + - `platform` (optional): String (e.g., `'github'`, `'discord'`, `'slack'`). |
| 9 | + - `after` (optional): DateTime parsable string (e.g., `'2025-09-01 00:00:00'`). |
| 10 | + - `before` (optional): DateTime parsable string (e.g., `'2025-09-30 23:59:59'`). |
| 11 | + - Output: |
| 12 | + - `date`: start of the day (daily bucket). |
| 13 | + - `count`: number of unique `activityId` per day, after filters. |
| 14 | + - Performance: |
| 15 | + - With ~1–2k rows/day and ≤30 days, `uniqExact` is typically fine. `uniqCombined` offers lower latency with negligible error for this scale. |
| 16 | + - Filters are pushed into `PREWHERE` to minimize I/O (segment/time first). |
| 17 | + |
| 18 | +TAGS "Activity metrics" |
| 19 | + |
| 20 | +NODE daily_counts |
| 21 | +SQL > |
| 22 | + % |
| 23 | + SELECT toStartOfDay(timestamp) AS date, uniqExact(activityId) AS count |
| 24 | + FROM |
| 25 | + activityRelations_deduplicated_ds |
| 26 | + PREWHERE |
| 27 | + "segmentId" IN {{ Array(segmentIds, 'String', required=True, description="Segment IDs") }} |
| 28 | + {% if defined(after) %} AND timestamp >= parseDateTimeBestEffort({{ String(after) }}) {% end %} |
| 29 | + {% if defined(before) %} |
| 30 | + AND timestamp <= parseDateTimeBestEffort({{ String(before) }}) |
| 31 | + {% end %} |
| 32 | + WHERE {% if defined(platform) %} platform = {{ String(platform) }} {% else %} 1 {% end %} |
| 33 | + GROUP BY date |
| 34 | + ORDER BY date ASC |
0 commit comments