How do I create a job that selects assets based on some metadata? #17912
-
Suppose I have a set of assets from dagster import Definitions, asset, define_asset_job
@asset(metadata={'odd': True})
def asset1():
return 'one'
@asset
def asset2(asset1):
return 'two'
@asset(metadata={'odd': True})
def asset3():
return 'three' I want create an asset job that just selects assets that have metadata matching |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's not the prettiest, but you could do something like this @asset(metadata={'odd': True})
def asset1():
return 'one'
@asset
def asset2(asset1):
return 'two'
@asset(metadata={'odd': True})
def asset3():
return 'three'
all_assets = [asset1, asset2, asset3]
odd_assets = []
for a in all_assets:
if a.metadata_by_key[a.key].get("odd", False):
odd_assets.append(a)
odd_job = define_asset_job(name="odd_job", selection=odd_assets)
defs = Definitions(
assets=all_assets,
jobs=[odd_job]
) How you create the initial list of all assets could be done with a manually maintained list, or with |
Beta Was this translation helpful? Give feedback.
It's not the prettiest, but you could do something like this
How you create the initial list of all assets could be done with a manually maintained list, or with
load_assets_from_package_module
or similar type function. If you haveSourceA…