-
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.
[dagster-airlift] assets_from_task (#23813)
adds a simple defs builder which ingests a list of specs for a particular dag/task id, to make the observe step more straightforward.
- Loading branch information
Showing
10 changed files
with
119 additions
and
67 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
43 changes: 43 additions & 0 deletions
43
examples/experimental/dagster-airlift/dagster_airlift/core/defs_builders.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,43 @@ | ||
from typing import Sequence, Union | ||
|
||
from dagster import AssetsDefinition, AssetSpec | ||
from dagster._core.definitions.asset_key import CoercibleToAssetKey | ||
from dagster._core.definitions.definitions_class import Definitions | ||
from typing_extensions import TypeAlias | ||
|
||
from .utils import DAG_ID_TAG, TASK_ID_TAG | ||
|
||
CoercibleToAssetSpec: TypeAlias = Union[AssetSpec, CoercibleToAssetKey] | ||
|
||
|
||
def specs_from_task( | ||
*, task_id: str, dag_id: str, assets: Sequence[CoercibleToAssetSpec] | ||
) -> Sequence[AssetSpec]: | ||
"""Construct a Dagster :py:class:`Definitions` object from a provided set of assets, | ||
with a mapping to which airflow task produces those assets. | ||
""" | ||
return [ | ||
asset | ||
if isinstance(asset, AssetSpec) | ||
else AssetSpec(key=asset, tags={DAG_ID_TAG: dag_id, TASK_ID_TAG: task_id}) | ||
for asset in assets | ||
] | ||
|
||
|
||
def combine_defs(*defs: Union[AssetsDefinition, Definitions, AssetSpec]) -> Definitions: | ||
"""Combine provided :py:class:`Definitions` objects and assets into a single object, which contains all constituent definitions.""" | ||
assets = [] | ||
for _def in defs: | ||
if isinstance(_def, Definitions): | ||
continue | ||
elif isinstance(_def, AssetsDefinition): | ||
assets.append(_def) | ||
elif isinstance(_def, AssetSpec): | ||
assets.append(_def) | ||
else: | ||
raise Exception(f"Unexpected type: {type(_def)}") | ||
|
||
return Definitions.merge( | ||
*[the_def for the_def in defs if isinstance(the_def, Definitions)], | ||
Definitions(assets=assets), | ||
) |
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
2 changes: 1 addition & 1 deletion
2
...mental/dagster-airlift/examples/dbt-example/dbt_example/shared/dbt/models/iris_setosa.sql
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 +1 @@ | ||
select * from {{ source('iris_dataset', 'iris_lakehouse_table') }} where species = 'Iris-setosa' | ||
select * from {{ source('lakehouse', 'iris_lakehouse_table') }} where species = 'Iris-setosa' |
4 changes: 2 additions & 2 deletions
4
...perimental/dagster-airlift/examples/dbt-example/dbt_example/shared/dbt/models/sources.yml
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,8 +1,8 @@ | ||
version: 2 | ||
|
||
sources: | ||
- name: iris_dataset | ||
- name: lakehouse | ||
database: jaffle_shop | ||
schema: iris_dataset | ||
schema: lakehouse | ||
tables: | ||
- name: iris_lakehouse_table |
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