feat(snuba): Add FUNCTION_COLLECT_UNIQUE for array-returning aggregations - #393
Merged
Conversation
|
The latest Buf updates on your PR. Results from workflow ci / buf-checks (pull_request).
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3f587fb. Configure here.
onewland
reviewed
Aug 5, 2026
onewland
approved these changes
Aug 6, 2026
pbhandari
force-pushed
the
feat/collect-unique-aggregation
branch
from
August 6, 2026 16:11
3f587fb to
2be3151
Compare
4 tasks
pbhandari
added a commit
to getsentry/snuba
that referenced
this pull request
Aug 10, 2026
…temTable (#8256) ## Summary Adds support for `FUNCTION_COLLECT_UNIQUE` in the TraceItemTable endpoint. Unlike every other aggregation — which reduces a group to a single scalar — this one gathers each group's distinct scalar values into an array, returned as a `val_array` in the response. It maps to ClickHouse's `groupUniqArray`. ## Related - Linear: [EAP-623 — Array aggregation support for GetTraceItemTable](https://linear.app/getsentry/issue/EAP-623/array-aggregation-support-for-gettraceitemtable) - Proto PR (adds the `FUNCTION_COLLECT_UNIQUE` enum value this consumes): getsentry/sentry-protos#393 ## Changes **Aggregation expression (`aggregation.py`)** - Map `FUNCTION_COLLECT_UNIQUE` to `groupUniqArrayIf(max_array_size)`, in both the plain and `FUNCTION_ANY`-style non-rounded branches (the result is an array, so `round()` must not be applied). - Reject extrapolation for `FUNCTION_COLLECT_UNIQUE`: scaling a set of values by a sampling weight is meaningless, so `get_extrapolated_function` raises `BadSnubaRPCRequestException` rather than silently producing a nonsensical result. - Refactored `get_extrapolated_function` to hoist the shared `condition` and `rounded_sampling_weight` sub-expressions out of the per-function map, removing the repeated inline `and_cond(...)` / cast boilerplate. **Response conversion (`trace_item_table.py`)** - New `_get_aggregate_converter` centralizes the aggregate-result → `AttributeValue` mapping: `FUNCTION_COLLECT_UNIQUE` → array converter, `FUNCTION_ANY` → key-typed converter, everything else → double. Replaces the duplicated `FUNCTION_ANY` special-casing across the `aggregation` and `conditional_aggregation` branches. **Config (`schema.json`)** - New `snuba_query_max_array_size` option (default 1000). Bounds how many distinct values `groupUniqArray` accumulates per group. Unlike `uniq`, `groupUniqArray` holds every distinct value on the aggregating node, so this caps its memory footprint; a group exceeding the limit is truncated rather than allowed to grow unbounded. ## Tests - `test_aggregation.py`: `FUNCTION_COLLECT_UNIQUE` is rejected under every extrapolation mode, and produces a `groupUniqArrayIf` expression when extrapolation is off. - `test_endpoint_trace_item_table.py`: end-to-end coverage for the aggregation (returns `val_array` per group) and for the conditional-aggregation variant (collects distinct values of one column filtered on another). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Adds
FUNCTION_COLLECT_UNIQUE = 14to the snubaFunctionenum intrace_item_attribute.proto. Unlike the existing aggregations that reduce a group to a scalar, this one collects each group's distinct values into an array (backed by ClickHousegroupUniqArray) and is returned as aval_arrayonTraceItemTable.Includes the regenerated Rust bindings and
Cargo.lockbump per the repo's codegen workflow.Related
🤖 Generated with Claude Code