-
Notifications
You must be signed in to change notification settings - Fork 35
feat: Search annotations in pipeline run API #107
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 all commits
Commits
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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 |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| import base64 | ||
| import dataclasses | ||
| import datetime | ||
| import json | ||
| import logging | ||
| import typing | ||
| from typing import Any, Final, Optional | ||
|
|
@@ -12,7 +10,7 @@ | |
| from . import backend_types_sql as bts | ||
| from . import component_structures as structures | ||
| from . import errors | ||
| from . import filter_query_models | ||
| from . import filter_query_sql | ||
|
|
||
| if typing.TYPE_CHECKING: | ||
| from cloud_pipelines.orchestration.storage_providers import ( | ||
|
|
@@ -69,8 +67,6 @@ class ListPipelineJobsResponse: | |
|
|
||
| class PipelineRunsApiService_Sql: | ||
| _PIPELINE_NAME_EXTRA_DATA_KEY = "pipeline_name" | ||
| _PAGE_TOKEN_OFFSET_KEY: Final[str] = "offset" | ||
| _PAGE_TOKEN_FILTER_KEY: Final[str] = "filter" | ||
| _DEFAULT_PAGE_SIZE: Final[int] = 10 | ||
|
|
||
| def create( | ||
|
|
@@ -173,22 +169,12 @@ def list( | |
| include_pipeline_names: bool = False, | ||
| include_execution_stats: bool = False, | ||
| ) -> ListPipelineJobsResponse: | ||
| if filter and filter_query: | ||
| raise errors.ApiValidationError( | ||
| "Cannot use both 'filter' and 'filter_query'. Use one or the other." | ||
| ) | ||
|
|
||
| if filter_query: | ||
| filter_query_models.FilterQuery.model_validate_json(filter_query) | ||
| raise NotImplementedError("filter_query is not yet implemented.") | ||
|
|
||
| filter_value, offset = _resolve_filter_value( | ||
| filter=filter, | ||
| page_token=page_token, | ||
| ) | ||
| where_clauses, next_page_filter_value = _build_filter_where_clauses( | ||
| filter_value=filter_value, | ||
| where_clauses, offset, next_token = filter_query_sql.build_list_filters( | ||
| filter_value=filter, | ||
| filter_query_value=filter_query, | ||
| page_token_value=page_token, | ||
| current_user=current_user, | ||
| page_size=self._DEFAULT_PAGE_SIZE, | ||
| ) | ||
|
|
||
| pipeline_runs = list( | ||
|
|
@@ -200,14 +186,10 @@ def list( | |
| .limit(self._DEFAULT_PAGE_SIZE) | ||
| ).all() | ||
| ) | ||
| next_page_offset = offset + self._DEFAULT_PAGE_SIZE | ||
| next_page_token_dict = { | ||
| self._PAGE_TOKEN_OFFSET_KEY: next_page_offset, | ||
| self._PAGE_TOKEN_FILTER_KEY: next_page_filter_value, | ||
| } | ||
| next_page_token = _encode_page_token(next_page_token_dict) | ||
| if len(pipeline_runs) < self._DEFAULT_PAGE_SIZE: | ||
| next_page_token = None | ||
|
|
||
| next_page_token = ( | ||
| next_token if len(pipeline_runs) >= self._DEFAULT_PAGE_SIZE else None | ||
| ) | ||
|
|
||
| return ListPipelineJobsResponse( | ||
| pipeline_runs=[ | ||
|
|
@@ -348,88 +330,6 @@ def delete_annotation( | |
| session.commit() | ||
|
|
||
|
|
||
| def _resolve_filter_value( | ||
| *, | ||
| filter: str | None, | ||
| page_token: str | None, | ||
| ) -> tuple[str | None, int]: | ||
| """Decode page_token and return the effective (filter_value, offset). | ||
|
|
||
| If a page_token is present, its stored filter takes precedence over the | ||
| raw filter parameter (the token carries the resolved filter forward across pages). | ||
| """ | ||
| page_token_dict = _decode_page_token(page_token) | ||
| offset = page_token_dict.get( | ||
| PipelineRunsApiService_Sql._PAGE_TOKEN_OFFSET_KEY, | ||
| 0, | ||
| ) | ||
| if page_token: | ||
| filter = page_token_dict.get( | ||
| PipelineRunsApiService_Sql._PAGE_TOKEN_FILTER_KEY, | ||
| None, | ||
| ) | ||
| return filter, offset | ||
|
|
||
|
|
||
| def _build_filter_where_clauses( | ||
| *, | ||
| filter_value: str | None, | ||
| current_user: str | None, | ||
| ) -> tuple[list[sql.ColumnElement], str | None]: | ||
| """Parse a filter string into SQLAlchemy WHERE clauses. | ||
|
|
||
| Returns (where_clauses, next_page_filter_value). The second value is the | ||
| filter string with shorthand values resolved (e.g. "created_by:me" becomes | ||
| "created_by:[email protected]") so it can be embedded in the next page token. | ||
| """ | ||
| where_clauses: list[sql.ColumnElement] = [] | ||
| parsed_filter = _parse_filter(filter_value) if filter_value else {} | ||
| for key, value in parsed_filter.items(): | ||
| if key == "_text": | ||
| raise NotImplementedError("Text search is not implemented yet.") | ||
| elif key == "created_by": | ||
| if value == "me": | ||
| if current_user is None: | ||
| current_user = "" | ||
| value = current_user | ||
| # TODO: Maybe make this a bit more robust. | ||
| # We need to change the filter since it goes into the next_page_token. | ||
| filter_value = filter_value.replace( | ||
| "created_by:me", f"created_by:{current_user}" | ||
| ) | ||
| if value: | ||
| where_clauses.append(bts.PipelineRun.created_by == value) | ||
| else: | ||
| where_clauses.append(bts.PipelineRun.created_by == None) | ||
| else: | ||
| raise NotImplementedError(f"Unsupported filter {filter_value}.") | ||
| return where_clauses, filter_value | ||
|
|
||
|
|
||
| def _decode_page_token(page_token: str) -> dict[str, Any]: | ||
| return json.loads(base64.b64decode(page_token)) if page_token else {} | ||
|
|
||
|
|
||
| def _encode_page_token(page_token_dict: dict[str, Any]) -> str: | ||
| return (base64.b64encode(json.dumps(page_token_dict).encode("utf8"))).decode( | ||
| "utf-8" | ||
| ) | ||
|
|
||
|
|
||
| def _parse_filter(filter: str) -> dict[str, str]: | ||
| # TODO: Improve | ||
| parts = filter.strip().split() | ||
| parsed_filter = {} | ||
| for part in parts: | ||
| key, sep, value = part.partition(":") | ||
| if sep: | ||
| parsed_filter[key] = value | ||
| else: | ||
| parsed_filter.setdefault("_text", "") | ||
| parsed_filter["_text"] += part | ||
| return parsed_filter | ||
|
|
||
|
|
||
| # ========== ExecutionNodeApiService_Sql | ||
|
|
||
|
|
||
|
|
||
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.
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.