-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into nikki/docs/guides-structure
- Loading branch information
Showing
15 changed files
with
588 additions
and
56 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
84 changes: 84 additions & 0 deletions
84
python_modules/dagster/dagster/_core/execution/context/metadata_logging.py
This file contains 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,84 @@ | ||
from typing import Any, Mapping, Optional, Union | ||
|
||
from dagster._core.definitions.asset_key import AssetKey | ||
from dagster._record import record | ||
from dagster._utils.merger import merge_dicts | ||
|
||
|
||
@record | ||
class OutputMetadataHandle: | ||
output_name: str | ||
mapping_key: Optional[str] | ||
|
||
|
||
@record | ||
class AssetMetadataHandle: | ||
asset_key: AssetKey | ||
partition_key: Optional[str] | ||
|
||
|
||
@record | ||
class OutputMetadataAccumulator: | ||
per_output_metadata: Mapping[ | ||
Union[OutputMetadataHandle, AssetMetadataHandle], Mapping[str, Any] | ||
] | ||
|
||
@staticmethod | ||
def empty() -> "OutputMetadataAccumulator": | ||
return OutputMetadataAccumulator(per_output_metadata={}) | ||
|
||
def get_output_metadata( | ||
self, output_name: str, mapping_key: Optional[str] | ||
) -> Mapping[str, Any]: | ||
handle = OutputMetadataHandle( | ||
output_name=output_name, | ||
mapping_key=mapping_key, | ||
) | ||
return self.per_output_metadata.get(handle, {}) | ||
|
||
def get_asset_metadata( | ||
self, asset_key: AssetKey, partition_key: Optional[str] | ||
) -> Mapping[str, Any]: | ||
handle = AssetMetadataHandle( | ||
asset_key=asset_key, | ||
partition_key=partition_key, | ||
) | ||
return self.per_output_metadata.get(handle, {}) | ||
|
||
def with_additional_output_metadata( | ||
self, | ||
output_name: str, | ||
mapping_key: Optional[str], | ||
metadata: Mapping[str, Any], | ||
) -> "OutputMetadataAccumulator": | ||
return self._with_metadata( | ||
handle=OutputMetadataHandle( | ||
output_name=output_name, | ||
mapping_key=mapping_key, | ||
), | ||
metadata=metadata, | ||
) | ||
|
||
def _with_metadata( | ||
self, handle: Union[OutputMetadataHandle, AssetMetadataHandle], metadata: Mapping[str, Any] | ||
) -> "OutputMetadataAccumulator": | ||
return OutputMetadataAccumulator( | ||
per_output_metadata=merge_dicts( | ||
self.per_output_metadata, | ||
{handle: merge_dicts(self.per_output_metadata.get(handle, {}), metadata)}, | ||
) | ||
) | ||
|
||
def with_additional_asset_metadata( | ||
self, | ||
asset_key: AssetKey, | ||
partition_key: Optional[str], | ||
metadata: Mapping[str, Any], | ||
) -> "OutputMetadataAccumulator": | ||
return self._with_metadata( | ||
handle=AssetMetadataHandle( | ||
asset_key=asset_key, | ||
partition_key=partition_key, | ||
), | ||
metadata=metadata, | ||
) |
Oops, something went wrong.