Skip to content

How do I create a job that selects assets based on some metadata? #17912

Answered by jamiedemaria
gnilrets asked this question in Q&A
Discussion options

You must be logged in to vote

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 load_assets_from_package_module or similar type function. If you have SourceA…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@gnilrets
Comment options

Answer selected by gnilrets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
area: ops/graphs/jobs Related to Dagster ops, graphs and jobs area: asset Related to Software-Defined Assets
2 participants