Replies: 4 comments 4 replies
-
Hi!
In both assets I found that |
Beta Was this translation helpful? Give feedback.
-
Another example that shows how you might mix an asset factory with regular from dagster import asset, Definitions, AssetIn
assets_to_make = ["a", "b", "c"]
def make_assets(asset_to_make):
@asset(
name=asset_to_make
)
def asset_template():
print(asset_to_make)
return
return asset_template
factory_assets = [make_assets(key) for key in assets_to_make]
factory_assets_ins = dict(zip(assets_to_make, [AssetIn(i) for i in assets_to_make]))
@asset
def downstream_of_factory_one(a):
pass
@asset(
ins=factory_assets_ins
)
def downstream_of_factory_all(**kwargs):
pass
defs = Definitions(
assets=[*factory_assets, downstream_of_factory_one, downstream_of_factory_all]
) |
Beta Was this translation helpful? Give feedback.
-
We're doing something similar but reading sql from files and executing it using an IO Manager: def sql_asset_factory(
name: str,
non_argument_deps: set[str] = {},
io_manager_key: str = "pudl_sqlite_io_manager",
compute_kind: str = "SQL",
) -> AssetsDefinition:
"""Factory for creating assets that run SQL statements."""
@asset(
name=name,
non_argument_deps=non_argument_deps,
io_manager_key=io_manager_key,
compute_kind=compute_kind,
)
def sql_view_asset() -> str:
"""Asset that creates sql view in a database."""
sql_path_traversable = importlib.resources.files("pudl.output.sql").joinpath(
f"{name}.sql"
)
try:
with importlib.resources.as_file(sql_path_traversable) as sql_path:
return sql_path.read_text()
# Raise a helpful error here if a sql file doesn't exist
except FileNotFoundError:
raise FileNotFoundError(
f"Could not find {sql_path}. Create a sql file in pudl.output.sql subpackage for {name} asset."
)
return sql_view_asset |
Beta Was this translation helpful? Give feedback.
-
We also have this YAML DSL for Asset Graphs Example |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
All reactions