Skip to content
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

interface for ExtContext and AssetExecutionContext #16480

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 66 additions & 2 deletions python_modules/dagster-pipes/dagster_pipes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,70 @@ def make_channel(
# ########################


class IContext(ABC):
"""Base class for asset context implemented by AssetExecutionContext and ExtContext."""

@property
@abstractmethod
def asset_key(self):
"""The AssetKey for the asset being materialized. If no asset is being materialized, errors. If
multiple assets are being materialized (as in a @multi_asset), errors.
"""

@property
@abstractmethod
def asset_keys(self):
"""The AssetKeys for the asset being materialized. If no asset is being materialized, errors."""

@property
@abstractmethod
def provenance(self):
"""The data provenance for the asset being materialized. If no asset is being materialized, errors. If
multiple assets are being materialized (as in a @multi_asset), errors.
"""

@property
@abstractmethod
def provenance_by_asset_key(self):
"""A dictionary of data provenance for the assets being materialized, keyed by asset key.
If no asset is being materialized, errors.
"""

@property
@abstractmethod
def code_version(self):
"""The code version for the asset being materialized. If no asset is being materialized, errors. If
multiple assets are being materialized (as in a @multi_asset), errors.
"""

@property
@abstractmethod
def code_version_by_asset_key(self):
"""A dictionary of code versions for the assets being materialized, keyed by asset key.
If no asset is being materialized, errors.
"""

@property
@abstractmethod
def is_partitioned(self) -> bool:
"""True if the current execution is partitioned."""

@property
@abstractmethod
def run_id(self) -> str:
"""The run id of the current execution."""

@property
@abstractmethod
def job_name(self) -> Optional[str]:
"""The name of the job that is executing."""

@property
@abstractmethod
def retry_number(self) -> int:
"""The number of retries of this execution."""


def init_dagster_ext(
*,
context_loader: Optional[ExtContextLoader] = None,
Expand Down Expand Up @@ -650,7 +714,7 @@ def init_dagster_ext(
return context


class ExtContext:
class ExtContext(IContext):
_instance: ClassVar[Optional["ExtContext"]] = None

@classmethod
Expand Down Expand Up @@ -734,7 +798,7 @@ def code_version_by_asset_key(self) -> Mapping[str, Optional[str]]:
return code_version_by_asset_key

@property
def is_partition_step(self) -> bool:
def is_partitioned(self) -> bool:
return self._data["partition_key_range"] is not None

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_multi_asset_context():
def test_no_partition_context():
context = _make_external_execution_context()

assert not context.is_partition_step
assert not context.is_partitioned
_assert_undefined(context, "partition_key")
_assert_undefined(context, "partition_key_range")
_assert_undefined(context, "partition_time_window")
Expand All @@ -147,7 +147,7 @@ def test_single_partition_context():
partition_time_window=None,
)

assert context.is_partition_step
assert context.is_partitioned
assert context.partition_key == "foo"
assert context.partition_key_range == partition_key_range
assert context.partition_time_window is None
Expand All @@ -163,7 +163,7 @@ def test_multiple_partition_context():
partition_time_window=time_window,
)

assert context.is_partition_step
assert context.is_partitioned
_assert_undefined(context, "partition_key")
assert context.partition_key_range == partition_key_range
assert context.partition_time_window == time_window
Expand Down