I have an asset that makes multiple assets. I have...
# ask-community
y
I have an asset that makes multiple assets. I have to make it a graph?
from documentation
Copy code
@graph(out={"first_asset": GraphOut(), "second_asset": GraphOut()})
def two_assets_graph(upstream_asset):
s
i think you can do asset one separately, so that it serves as an input to the downstream ones
Copy code
@asset
def my_upstream_asset():
    return [1,2,3]

@multi_asset(...) # however that works
def my_multi_downstream_asset(my_upstream_asset):
    downstream_one = my_upstream_asset + [3,4,5]
    downstream_two = my_upstream_asset + [6,7,8]
    return downstream_one, downstream_two
y
oh gotcha! ok thanks
why would one use a graph instead? I didn't quite get the explanation in the docs
s
i'd say that, in the "old world" that focused on building DAGs, the "graph" is a useful way to make highly reusable jobs. (step 1 then step 2 then step 3.) in the assets world, graphs are probably a bit unnecessary from a user perspective, and perhaps even an anti-pattern, because it makes you think about the process rather than the product of the process. (although dagster uses graphs under the hood to chain assets together.)
c
One reason why you would use a graph-backed asset is to reuse existing ops. Another reason would be that you want to use intermediate outputs from ops without having to bind those outputs to assets.
👍 1
y
Thanks for the explanation. How does a graph-backed asset let you reuse an existing op, though? You just mean if you wrote it as an op before already?
c
@Yang Yes, that's right--if you have an existing op that does some complex computation, you can include that op as part of a graph-backed asset
y
oh ok gotcha, thanks
finally getting back to this. a followup question is that I want to double check how to use some outputs in downstream assets. will this work?
Copy code
@asset
def using_downstream_one(downstream_one):
    etc
c
Yes, that's right. Dagster will assume that the parameter name is the asset key of the upstream asset. If you want to be more explicit about this, you could also define an explicit dependency: https://docs.dagster.io/concepts/assets/software-defined-assets#defining-explicit-dependencies
y
ok great I'm a bit confused by this example, though
Copy code
# If it has multiple segments, you can provide a list:
@asset(ins={"upstream": AssetIn(key=["some_db_schema", "upstream_asset"])})
def another_downstream_asset(upstream):
    return upstream + [10]
what does the upstream asset look like in this case?
Copy code
@asset(???)
def upstream_asset():
    return [1, 2, 3]
thanks
c
In this case, the upstream asset would contain a key prefix:
Copy code
@asset(key_prefix=['some_db_schema'])
def upstream_asset():
    return [1, 2, 3]


@asset(ins={"upstream": AssetIn(key=["some_db_schema", "upstream_asset"])})
def another_downstream_asset(upstream):
    return upstream + [10]