Dominik Lotz
02/27/2024, 6:27 AMScout
02/27/2024, 6:27 AM@asset
decorator. 2. Define the graph that should be orchestrated after "load_all" is materialized. This graph will consist of ops, which are the building blocks of computation in Dagster. 3. Use the @graph
decorator to define the graph. 4. Create an asset from the graph using AssetsDefinition.from_graph
if you want the graph's execution to result in the creation of new assets. 5. Set up the dependency such that the graph is dependent on the "load_all" asset. This means that the graph will only execute after "load_all" has been materialized. Here is an example code snippet that illustrates how you might set this up, using the @asset
and @graph
decorators, as well as the AssetsDefinition.from_graph
method: python from dagster import asset, graph, op, AssetsDefinition @asset def load_all(): # Logic to load data pass @op def process_data(data): # Logic to process data pass @graph def process_graph(load_all_data): return process_data(load_all_data) # Create an asset from the graph, with load_all as an upstream dependency process_assets = AssetsDefinition.from_graph( graph_def=process_graph, keys_by_input_name={"load_all_data": AssetKey("load_all")}, ) # Now, when you materialize the 'load_all' asset, the 'process_graph' will be orchestrated after it.
Please note that the actual implementation may vary based on your specific use case and the structure of your data pipeline. The provided example is a simplified illustration and should be adapted to fit the context of your application. If you need more detailed guidance or have a more complex scenario, please refer to the Dagster documentation or reach out with specific questions.Dominik Lotz
02/27/2024, 7:00 AM@graph_asset
Scout
02/27/2024, 7:00 AM@graph_asset
decorator, you can define a graph-backed asset that will be computed after another asset, such as "load_all", is materialized. The @graph_asset
decorator allows you to define an asset that's computed using a graph of ops, with dependencies between the ops specified inside the body of the decorated function. Here's how you can orchestrate a graph after the "load_all" asset is materialized using `@graph_asset`: 1. Define your "load_all" asset using the @asset
decorator. 2. Define the ops that will be part of your graph. 3. Use the @graph_asset
decorator to define a new asset that depends on "load_all". Inside the @graph_asset
function, you will invoke the ops that make up your graph. Here's an example: python from dagster import asset, op, graph_asset @asset def load_all(): # Logic to load data pass @op def process_data(data): # Logic to process data pass @graph_asset def my_graph_asset(load_all_data): # 'load_all_data' is the materialized asset 'load_all' return process_data(load_all_data) # When you materialize the 'load_all' asset, the 'my_graph_asset' will be orchestrated after it.
In this example, my_graph_asset
is a graph-backed asset that depends on the load_all
asset. When load_all
is materialized, my_graph_asset
will be triggered, and the process_data
op will be executed with the data from load_all
. Remember to define the dependencies correctly so that Dagster knows to execute my_graph_asset
after load_all
has been materialized. The documentation provides more details and examples on how to use @graph_asset
and set up dependencies between assets.