-
Notifications
You must be signed in to change notification settings - Fork 18
feat(entities): add grouped count queries #837
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f5d1d4e
feat(entities): add grouped entity counts
callingmedic911 8487614
feat(entities): expose grouped counts in list API
callingmedic911 0cc8171
feat(entities): add client count helper
callingmedic911 b525430
refactor(entities): simplify grouped count implementation
callingmedic911 941a3b1
chore(openapi): refresh entity grouped counts contract
callingmedic911 5ad127f
fix(entities): harden grouped count results
callingmedic911 64ed8ca
fix(entities): validate grouped count fields
callingmedic911 3f470bb
fix(entities): preserve null string group keys
callingmedic911 91b9d12
docs: narrow entity grouped count design
callingmedic911 22da54b
refactor(entities): narrow grouped counts
callingmedic911 58ea3a0
fix(entities): validate empty count field
callingmedic911 963263a
refactor(entities): narrow grouped count client
callingmedic911 0ac25e4
chore(entities): finalize narrow grouped counts
callingmedic911 c185259
chore(entities): apply final-review cleanup to grouped counts
callingmedic911 91f68e7
fix(entities): decode grouped JSON string values
callingmedic911 43f997a
Merge branch 'main' into entity-count-by/aditypandey
callingmedic911 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from unittest.mock import AsyncMock, Mock | ||
|
|
||
| import pytest | ||
| from nemo_platform.types.entities import EntitiesPage | ||
| from nemo_platform.types.shared.pagination_data import PaginationData | ||
| from nemo_platform_plugin.entities import EntityClient, EntityStoreError | ||
|
|
||
|
|
||
| class ExperimentGroup: | ||
| __entity_type__ = "experiment_group" | ||
|
|
||
|
|
||
| def _entities_page(group_counts: dict[str, int] | None = None) -> EntitiesPage: | ||
| return EntitiesPage.model_construct( | ||
| data=[], | ||
| pagination=PaginationData(page=1, page_size=1, current_page_size=0, total_pages=0, total_results=0), | ||
| group_counts=group_counts, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_count_by_returns_grouped_counts_for_shorthand_filter() -> None: | ||
| mock_api = Mock() | ||
| mock_api.list = AsyncMock(return_value=_entities_page(group_counts={"insight-a": 2})) | ||
| client = EntityClient(mock_api) | ||
|
|
||
| counts = await client.count_by( | ||
| ExperimentGroup, | ||
| "insight_id", | ||
| filter_obj={ | ||
| "insight_id": {"$in": ["insight-a"]}, | ||
| "is_deleted": False, | ||
| }, | ||
| ) | ||
|
|
||
| assert counts == {"insight-a": 2} | ||
| assert mock_api.list.await_args.kwargs["filter"] == ( | ||
| '{"data.insight_id": {"$in": ["insight-a"]}, "data.is_deleted": false}' | ||
| ) | ||
| assert mock_api.list.await_args.kwargs["extra_query"] == {"count_by": "data.insight_id"} | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_count_by_rejects_response_without_grouped_counts() -> None: | ||
| mock_api = Mock() | ||
| mock_api.list = AsyncMock(return_value=_entities_page()) | ||
| client = EntityClient(mock_api) | ||
|
|
||
| with pytest.raises(EntityStoreError, match="Grouped counts not found"): | ||
| await client.count_by(ExperimentGroup, "insight_id") | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_count_by_rejects_non_direct_field() -> None: | ||
| mock_api = Mock() | ||
| client = EntityClient(mock_api) | ||
|
|
||
| with pytest.raises(ValueError, match="direct entity data field"): | ||
| await client.count_by(ExperimentGroup, "data.insight_id") |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.