-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose metadata on AssetNode (and source assets) directly (#6900)
- Loading branch information
Showing
8 changed files
with
115 additions
and
15 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
57 changes: 49 additions & 8 deletions
57
python_modules/dagster/dagster/core/asset_defs/source_asset.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 |
---|---|---|
@@ -1,25 +1,66 @@ | ||
from typing import Any, Dict, NamedTuple, Optional | ||
from typing import NamedTuple, Optional, Sequence, Union | ||
|
||
import dagster.check as check | ||
from dagster.core.definitions.events import AssetKey | ||
from dagster.core.definitions.metadata import ( | ||
MetadataEntry, | ||
MetadataMapping, | ||
MetadataUserInput, | ||
PartitionMetadataEntry, | ||
normalize_metadata, | ||
) | ||
from dagster.core.definitions.partition import PartitionsDefinition | ||
|
||
|
||
class SourceAsset(NamedTuple): | ||
class SourceAsset( | ||
NamedTuple( | ||
"_SourceAsset", | ||
[ | ||
("key", AssetKey), | ||
("metadata_entries", Sequence[Union[MetadataEntry, PartitionMetadataEntry]]), | ||
("io_manager_key", str), | ||
("description", Optional[str]), | ||
("partitions_def", Optional[PartitionsDefinition]), | ||
], | ||
) | ||
): | ||
"""A SourceAsset represents an asset that is not generated by any Dagster op in the repository | ||
that it's referenced from. | ||
Attributes: | ||
key (AssetKey): The key of the asset. | ||
metadata (Optional[Dict[str, Any]]): Metadata associated with the asset. | ||
metadata_entries (List[MetadataEntry]): Metadata associated with the asset. | ||
io_manager_key (str): The key for the IOManager that will be used to load the contents of | ||
the asset when it's used as an input to other assets inside a job. | ||
description (Optional[str]): The description of the asset. | ||
partitions_def (Optional[PartitionsDefinition]): Defines the set of partition keys that | ||
compose the asset. | ||
""" | ||
|
||
key: AssetKey | ||
metadata: Optional[Dict[str, Any]] = None | ||
io_manager_key: str = "io_manager" | ||
description: Optional[str] = None | ||
partitions_def: Optional[PartitionsDefinition] = None | ||
def __new__( | ||
cls, | ||
key: AssetKey, | ||
metadata: Optional[MetadataUserInput] = None, | ||
io_manager_key: str = "io_manager", | ||
description: Optional[str] = None, | ||
partitions_def: Optional[PartitionsDefinition] = None, | ||
): | ||
|
||
metadata = check.opt_dict_param(metadata, "metadata", key_type=str) | ||
metadata_entries = normalize_metadata(metadata, [], allow_invalid=True) | ||
|
||
return super().__new__( | ||
cls, | ||
key=check.inst_param(key, "key", AssetKey), | ||
metadata_entries=metadata_entries, | ||
io_manager_key=check.str_param(io_manager_key, "io_manager_key"), | ||
description=check.opt_str_param(description, "description"), | ||
partitions_def=check.opt_inst_param( | ||
partitions_def, "partitions_def", PartitionsDefinition | ||
), | ||
) | ||
|
||
@property | ||
def metadata(self) -> MetadataMapping: | ||
# PartitionMetadataEntry (unstable API) case is unhandled | ||
return {entry.label: entry.entry_data for entry in self.metadata_entries} # type: ignore |
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
19 changes: 19 additions & 0 deletions
19
python_modules/dagster/dagster_tests/core_tests/asset_defs_tests/test_source_asset.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,19 @@ | ||
from dagster.core.asset_defs.source_asset import SourceAsset | ||
from dagster.core.definitions.events import AssetKey | ||
from dagster.core.definitions.metadata import MetadataEntry, MetadataValue | ||
|
||
|
||
def test_source_asset_metadata(): | ||
sa = SourceAsset(key=AssetKey("foo"), metadata={"foo": "bar", "baz": object()}) | ||
assert sa.metadata_entries == [ | ||
MetadataEntry(label="foo", description=None, entry_data=MetadataValue.text("bar")), | ||
MetadataEntry( | ||
label="baz", | ||
description=None, | ||
entry_data=MetadataValue.text("[object] (unserializable)"), | ||
), | ||
] | ||
assert sa.metadata == { | ||
"foo": MetadataValue.text("bar"), | ||
"baz": MetadataValue.text("[object] (unserializable)"), | ||
} |
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
809665e
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.
Successfully deployed to the following URLs:
dagster – ./docs/next
docs.dagster.io
new-docs.dagster.io
dagster-git-master-elementl.vercel.app
dagster-elementl.vercel.app
dagster.vercel.app