-
Notifications
You must be signed in to change notification settings - Fork 5
Dataset pipelines #384
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
Open
Ankur Goyal (ankrgyl)
wants to merge
3
commits into
main
Choose a base branch
from
dataset-pipeline
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+243
−35
Open
Dataset pipelines #384
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,161 @@ | ||||
| from __future__ import annotations | ||||
|
Member
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. we can remove this
Suggested change
|
||||
|
|
||||
| from collections.abc import Awaitable, Sequence | ||||
| from dataclasses import dataclass | ||||
| from typing import Any, Generic, Literal, Protocol, TypeAlias, TypeVar | ||||
|
|
||||
| from typing_extensions import NotRequired, TypedDict | ||||
|
|
||||
| from .generated_types import ObjectReference | ||||
| from .logger import Metadata | ||||
| from .trace import Trace | ||||
|
|
||||
|
|
||||
| DatasetPipelineScope: TypeAlias = Literal["span", "trace"] | ||||
|
|
||||
|
|
||||
| class DatasetPipelineSource(TypedDict, total=False): | ||||
| project_id: str | ||||
| project_name: str | ||||
| org_name: str | ||||
| filter: str | ||||
| scope: DatasetPipelineScope | ||||
|
|
||||
|
|
||||
| @dataclass(frozen=True) | ||||
| class PipelineSource: | ||||
| filter: str | None = None | ||||
| scope: DatasetPipelineScope | None = None | ||||
| project_name: str | None = None | ||||
| project_id: str | None = None | ||||
| org_name: str | None = None | ||||
|
|
||||
| def as_dict(self) -> DatasetPipelineSource: | ||||
| return _drop_none( | ||||
| { | ||||
| "project_id": self.project_id, | ||||
| "project_name": self.project_name, | ||||
| "org_name": self.org_name, | ||||
| "filter": self.filter, | ||||
| "scope": self.scope, | ||||
| } | ||||
| ) | ||||
|
|
||||
|
|
||||
| class DatasetPipelineTarget(TypedDict): | ||||
| dataset_name: str | ||||
| project_id: NotRequired[str] | ||||
| project_name: NotRequired[str] | ||||
| org_name: NotRequired[str] | ||||
| description: NotRequired[str] | ||||
| metadata: NotRequired[Metadata] | ||||
|
|
||||
|
|
||||
| @dataclass(frozen=True) | ||||
| class PipelineTarget: | ||||
| dataset_name: str | ||||
| project_name: str | None = None | ||||
| project_id: str | None = None | ||||
| org_name: str | None = None | ||||
| description: str | None = None | ||||
| metadata: Metadata | None = None | ||||
|
|
||||
| def as_dict(self) -> DatasetPipelineTarget: | ||||
| return _drop_none( | ||||
| { | ||||
| "project_id": self.project_id, | ||||
| "project_name": self.project_name, | ||||
| "org_name": self.org_name, | ||||
| "dataset_name": self.dataset_name, | ||||
| "description": self.description, | ||||
| "metadata": self.metadata, | ||||
| } | ||||
| ) | ||||
|
|
||||
|
|
||||
| class DatasetPipelineRow(TypedDict, total=False): | ||||
| id: str | ||||
| input: Any | None | ||||
| expected: Any | None | ||||
| tags: Sequence[str] | None | ||||
| metadata: Metadata | None | ||||
| origin: ObjectReference | ||||
|
|
||||
|
|
||||
| Row = TypeVar("Row", bound=DatasetPipelineRow) | ||||
|
|
||||
|
|
||||
| class DatasetPipelineTransformArgs(TypedDict, total=False): | ||||
| input: Any | None | ||||
| output: Any | None | ||||
| metadata: Metadata | None | ||||
| expected: Any | None | ||||
| trace: Trace | ||||
|
|
||||
|
|
||||
| DatasetPipelineTransformResult: TypeAlias = Row | Sequence[Row] | None | ||||
| DatasetPipelineSourceLike: TypeAlias = DatasetPipelineSource | PipelineSource | ||||
| DatasetPipelineTargetLike: TypeAlias = DatasetPipelineTarget | PipelineTarget | ||||
|
|
||||
|
|
||||
| def _drop_none(values: dict[str, Any]) -> dict[str, Any]: | ||||
| return {key: value for key, value in values.items() if value is not None} | ||||
|
|
||||
|
|
||||
| def _normalize_source(source: DatasetPipelineSourceLike) -> DatasetPipelineSource: | ||||
| if isinstance(source, PipelineSource): | ||||
| return source.as_dict() | ||||
| return dict(source) | ||||
|
|
||||
|
|
||||
| def _normalize_target(target: DatasetPipelineTargetLike) -> DatasetPipelineTarget: | ||||
| if isinstance(target, PipelineTarget): | ||||
| return target.as_dict() | ||||
| return dict(target) | ||||
|
|
||||
|
|
||||
| class DatasetPipelineTransform(Protocol[Row]): | ||||
| def __call__( | ||||
| self, | ||||
| input: Any | None = None, | ||||
| output: Any | None = None, | ||||
| metadata: Metadata | None = None, | ||||
| expected: Any | None = None, | ||||
| trace: Trace | None = None, | ||||
| ) -> DatasetPipelineTransformResult[Row] | Awaitable[DatasetPipelineTransformResult[Row]]: ... | ||||
|
|
||||
|
|
||||
| @dataclass(frozen=True) | ||||
| class DatasetPipelineDefinition(Generic[Row]): | ||||
| source: DatasetPipelineSource | ||||
| transform: DatasetPipelineTransform[Row] | ||||
| target: DatasetPipelineTarget | ||||
| name: str | None = None | ||||
|
|
||||
|
|
||||
| _DATASET_PIPELINES: list[DatasetPipelineDefinition[Any]] = [] | ||||
|
|
||||
|
|
||||
| def get_registered_dataset_pipelines() -> list[DatasetPipelineDefinition[Any]]: | ||||
| return list(_DATASET_PIPELINES) | ||||
|
|
||||
|
|
||||
| def is_dataset_pipeline_definition(value: object) -> bool: | ||||
| return isinstance(value, DatasetPipelineDefinition) | ||||
|
|
||||
|
|
||||
| def DatasetPipeline( | ||||
| name: str | None = None, | ||||
| *, | ||||
| source: DatasetPipelineSourceLike, | ||||
| transform: DatasetPipelineTransform[DatasetPipelineRow], | ||||
| target: DatasetPipelineTargetLike, | ||||
| ) -> DatasetPipelineDefinition[DatasetPipelineRow]: | ||||
| definition = DatasetPipelineDefinition( | ||||
| name=name, | ||||
| source=_normalize_source(source), | ||||
| transform=transform, | ||||
| target=_normalize_target(target), | ||||
| ) | ||||
| _DATASET_PIPELINES.append(definition) | ||||
| return definition | ||||
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.
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.
We should add
__all__to the module so not everything here is exposed as public API.