https://dagster.io/ logo
#ask-ai
Title
# ask-ai
a

Andreas

02/29/2024, 7:52 AM
AssetSelection
👏 1
s

Scout

02/29/2024, 7:52 AM
AssetSelection
in Dagster is a powerful feature that allows you to define queries over a set of assets and asset checks. It is typically used with
define_asset_job()
to specify which assets should be included in a job. You can use operators like
|
,
&
, and
-
to create unions, intersections, and differences of selections, respectively. Here are some examples of how you can use `AssetSelection`: - To select all assets in a group "marketing":
Copy code
python   AssetSelection.groups("marketing")
- To select all assets in group "marketing", as well as the asset with key "promotion":
Copy code
python   AssetSelection.groups("marketing") | AssetSelection.keys("promotion")
- To select all assets in group "marketing" that are downstream of asset "leads":
Copy code
python   AssetSelection.groups("marketing") & AssetSelection.keys("leads").downstream()
- To select a list of assets:
Copy code
python   my_assets_list = [...]   AssetSelection.assets(*my_assets_list)
- To select all assets except for those in group "marketing":
Copy code
python   AssetSelection.all() - AssetSelection.groups("marketing")
- To select all assets which are materialized by the same op as "projections":
Copy code
python   AssetSelection.keys("projections").required_multi_asset_neighbors()
- To select all assets in group "marketing" and exclude their asset checks:
Copy code
python   AssetSelection.groups("marketing") - AssetSelection.all_asset_checks()
- To select all asset checks that target a list of assets:
Copy code
python   AssetSelection.checks_for_assets(*my_assets_list)
- To select a specific asset check:
Copy code
python   my_asset_check = ...   AssetSelection.checks(my_asset_check)
These are just a few examples of how
AssetSelection
can be used to create flexible and powerful asset queries for your jobs in Dagster. The
AssetSelection
class provides a variety of methods to help you select the assets you need for your data pipelines.
11 Views