How to materialize an @asset in a job of @ops #24246
Answered
by
garethbrickman
dennisgera
asked this question in
Q&A
-
Hi team, I'm currently attempting to materialize an asset from within a job of ops because one of my ops reads from that asset's data. I couldn't find a way to do this without repeating code. How does dagster recommend I materialize the asset before the op that reads from it starts in this case? Here's a redacted snippet of my code for reference: My Asset: @asset(
compute_kind="python",
key_prefix=["raw", "raw_wen"],
)
def wen_contacts(
context: OpExecutionContext,
wen_api: WenAPI,
config: RawConfig,
s3_resource: S3Resource,
postgres_database: PostgresClientResource,
):
data = wen_api.get_all_contacts(params=config.dict())
[...]
postgres_database.persist(
df=df,
procedure=PersistProcedureEnum.REPLACE if config.is_full_extraction else PersistProcedureEnum.UPSERT,
...
)
return MaterializeResult(metadata=metadata) My Job: @op
def get_current_contacts(analytics_warehouse: PostgresClientResource) -> pd.DataFrame:
# This table is updated every time my asset is materialized.
# That's why I want to materialize my asset prior to this op in this job.
return (
analytics_warehouse.query("select * from raw_wen.wen_contacts")
...
)
[...]
@op
def post_updates(update_df: pd.DataFrame, wen_api: WenAPI) -> None:
...
@job(
name="update_wen_contacts_job",
)
def update_weni_contacts_job():
# What should I do here to properly materialize my asset?
post_updates(get_contacts_to_update(latest_contacts=get_latest_contacts(), current_contacts=get_current_contacts())) |
Beta Was this translation helpful? Give feedback.
Answered by
garethbrickman
Sep 9, 2024
Replies: 1 comment 1 reply
-
Jobs are distinct between ops and assets. Two ways to try came to my mind:
But these may not be worth doing compared to repeating code. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
dennisgera
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Jobs are distinct between ops and assets. Two ways to try came to my mind:
But these may not be worth doing compared to repeating code.