-
-
Notifications
You must be signed in to change notification settings - Fork 62
feat(attribute-values): Add counts to response and orderby #7960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ | |
| from snuba.query.data_source.simple import Entity, LogicalDataSource | ||
| from snuba.query.dsl import Functions as f | ||
| from snuba.query.dsl import column | ||
| from snuba.query.expressions import Expression | ||
| from snuba.query.expressions import Expression, FunctionCall | ||
| from snuba.query.logical import Query | ||
| from snuba.query.query_settings import HTTPQuerySettings | ||
| from snuba.request import Request as SnubaRequest | ||
|
|
@@ -128,10 +128,20 @@ def _build_query( | |
| name="attr_value", | ||
| expression=f.distinct(column(attr_value.alias, alias="attr_value")), | ||
| ), | ||
| SelectedExpression( | ||
| name="count()", | ||
| expression=FunctionCall( | ||
| alias="count()", | ||
| function_name="count", | ||
| parameters=(), | ||
| ), | ||
| ), | ||
| ], | ||
| order_by=[ | ||
| OrderBy(direction=OrderByDirection.DESC, expression=column("count()")), | ||
| OrderBy(direction=OrderByDirection.ASC, expression=column("attr_value")), | ||
| ], | ||
| groupby=[column("attr_value")], | ||
| limit=request.limit, | ||
| offset=(request.page_token.offset if request.page_token.HasField("offset") else 0), | ||
| ) | ||
|
|
@@ -184,6 +194,7 @@ def _execute(self, in_msg: TraceItemAttributeValuesRequest) -> TraceItemAttribut | |
| if in_msg.key.name == "sentry.item_id" and in_msg.value_substring_match: | ||
| return TraceItemAttributeValuesResponse( | ||
| values=[in_msg.value_substring_match], | ||
| counts=[1], | ||
| page_token=None, | ||
| ) | ||
| in_msg.limit = in_msg.limit or 1000 | ||
|
|
@@ -193,14 +204,19 @@ def _execute(self, in_msg: TraceItemAttributeValuesRequest) -> TraceItemAttribut | |
| request=snuba_request, | ||
| timer=self._timer, | ||
| ) | ||
| values = [r["attr_value"] for r in res.result.get("data", [])] | ||
| values, counts = [], [] | ||
| for row in res.result.get("data", []): | ||
| values.append(row["attr_value"]) | ||
| counts.append(row.get("count()", 0)) | ||
| if len(values) == 0: | ||
| return TraceItemAttributeValuesResponse( | ||
| values=values, | ||
| counts=counts, | ||
| page_token=None, | ||
| ) | ||
| return TraceItemAttributeValuesResponse( | ||
| values=values, | ||
| counts=counts, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cursor-based page token incompatible with new sort orderMedium Severity The response Additional Locations (1)Reviewed by Cursor Bugbot for commit bf90686. Configure here. |
||
| page_token=( | ||
| PageToken(offset=in_msg.page_token.offset + len(values)) | ||
| if in_msg.page_token.HasField("offset") or len(values) == 0 | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant
distinctwrapper withGROUP BYclauseLow Severity
f.distinct()wrappingattr_valueis now redundant because the newgroupby=[column("attr_value")]already guarantees unique values. In ClickHouse, this generatesSELECT DISTINCT ... GROUP BY ...where theDISTINCTis a no-op. Keeping both deduplication mechanisms is confusing and obscures the query's actual semantics —GROUP BYis the operative deduplication here (needed forcount()).Reviewed by Cursor Bugbot for commit bf90686. Configure here.