https://dagster.io/ logo
#ask-community
Title
# ask-community
q

Qwame

08/23/2022, 7:18 PM
Hi all, how do I define a dbt run job using
define_asset_job
. I have models tagged
analytics
. I was hoping to run them all using
Copy code
define_asset_job("run_analytics", selection="tag:analytics")
However, i got an error saying
tag:analytics
is not a valid selection. I think if I change the selection to a model name, this would work, but what if I want to use tags? Any help?
r

rex

08/23/2022, 7:26 PM
If your models are contained within a group, you can use the
AssetSelection
API to select them: https://docs.dagster.io/_apidocs/assets#dagster.define_asset_job
so you would want something like
selection=AssetSelection.groups("analytics")
q

Qwame

08/23/2022, 7:43 PM
I see. So does this meanI have to use groups instead of tags to make this work?
And how can I break my dbt models into groups?
c

chris

08/24/2022, 12:33 AM
hey Qwame - you can actually select different sets of assets corresponding to your dbt tags; and create different jobs for those sets of assets. For example, you can call
load_assets_from_dbt_project(..., select="tag:events", node_info_to_group_fn=...)
to load only the assets with that tag, and give them all a group. Then, you can use the info rex gave above to subselect your assets based on group. Does that make sense?
q

Qwame

08/24/2022, 1:59 AM
Oh yeah, this makes a lot of sense. Question - how and when would you use the
node_info_to_group_fn
parameter?
Is that where I will pass the
group_name
etc.?
c

chris

08/24/2022, 5:51 PM
that's right - the
node_info_to_group_fn
produces an asset group name from the dbt node info; so for example you can pull information off of the tags to construct the group name.
Copy code
def _node_info_to_group(node_info):
    return node_info["tags"][0]
And you would pass that function as the value to the parameter
q

Qwame

08/24/2022, 9:07 PM
Thanks @chris, this works. I printed the
node_info
and noticed it was the
manifest.json
file. How is this not described anywhere in the docs?
c

chris

08/24/2022, 9:26 PM
It's described in the API docs, we have additional docs coming down the line for dbt-related stuff, but likely just an oversight