Replies: 5 comments 5 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.
-
How would I trigger these assets to conditionally materialize using RunRequests from a single sensor? ✏️ Use case: I have a sensor that detects whether a 3rd party JSON file has been updated. This JSON file is essentially a changelog for reports that we ingest. If a report has changes listed in the JSON file, we want to trigger an updated asset materialization for that report. I want to create the report assets via a factory pattern like yall show here, given we have hundreds. How do I get the sensor to trigger only those assets that have changes? 💭 Thoughts thus far: It looks like both Sensors and RunRequests share the |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
All reactions