Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to run a single dbt model as a task? #912

Closed
luis-fnogueira opened this issue Apr 11, 2024 · 2 comments
Closed

Is it possible to run a single dbt model as a task? #912

luis-fnogueira opened this issue Apr 11, 2024 · 2 comments
Labels
area:execution Related to the execution environment/mode, like Docker, Kubernetes, Local, VirtualEnv, etc area:parsing Related to parsing DAG/DBT improvement, issues, or fixes area:profile Related to ProfileConfig, like Athena, BigQuery, Clickhouse, Spark, Trino, etc dbt:run Primarily related to dbt run command or functionality
Milestone

Comments

@luis-fnogueira
Copy link

I am opening this issue because I couldn't run a single dbt model as task in Airflow with Cosmos with one profile config. I wouldn't like to run a DbtDag or a DbtTaskGroup with all my models in my dbt folder. I would like to run just one model, specifying its path, using only on profile.yml. Is that possible?

I ran:

    dbt_task= DbtTaskGroup(
        group_id="dbt_task",
        project_config=ProjectConfig(
            (dbt_root_path / "my_project/models/some_model/").as_posix(),
        ),
        operator_args={"install_deps": True},
        profile_config=profile_config,
        default_args={"retries": 2},
    )

But I get a cosmos.exceptions.CosmosValueError: Could not find dbt_project.yml at {path}. I should either copy the dbt_project.yml from root or set the project_config as dbt_root_path / "my_project/ path, but it finds all models.

Is there a way to run a single model as a task or I have to run all models in the project invariably?

@dosubot dosubot bot added area:execution Related to the execution environment/mode, like Docker, Kubernetes, Local, VirtualEnv, etc area:parsing Related to parsing DAG/DBT improvement, issues, or fixes area:profile Related to ProfileConfig, like Athena, BigQuery, Clickhouse, Spark, Trino, etc dbt:run Primarily related to dbt run command or functionality labels Apr 11, 2024
@tatiana
Copy link
Collaborator

tatiana commented Apr 25, 2024

Hi @luis-fnogueira , could you confirm which version of Cosmos you are using?

It seems there are two issues you're describing, that are unrelated:

1. Profile yml path

The error you described, cosmos.exceptions.CosmosValueError: Could not find dbt_project.yml at {path}, is related to not finding dbt_project.yml:

raise CosmosValueError(f"Could not find {name} at {path}")

Cosmos can reference this file in any directory as long as the process running Airflow has permission to access it.

  1. Running a single model

There are a few options. Similar to the dbt command, Cosmos exposes select and exclude. You could write a selector to pick the only model you're interested in running:
https://astronomer.github.io/astronomer-cosmos/configuration/selecting-excluding.html

Since you only want to run a model, another option would be to use a Cosmos operator directly, without the need of using DbtDag or DbtTaskGroup:

run_operator = DbtRunLocalOperator(
profile_config=real_profile_config,
project_dir=DBT_PROJ_DIR,
task_id="run",
dbt_cmd_flags=["--models", "stg_customers"],
install_deps=True,
append_env=True,
)

@tatiana tatiana added this to the 1.5.0 milestone May 17, 2024
@tatiana
Copy link
Collaborator

tatiana commented May 17, 2024

Since we don't have further details, we're closing this issue. Please, @luis-fnogueira reopen it with more information if you're still facing problems.

@tatiana tatiana closed this as completed May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:execution Related to the execution environment/mode, like Docker, Kubernetes, Local, VirtualEnv, etc area:parsing Related to parsing DAG/DBT improvement, issues, or fixes area:profile Related to ProfileConfig, like Athena, BigQuery, Clickhouse, Spark, Trino, etc dbt:run Primarily related to dbt run command or functionality
Projects
None yet
Development

No branches or pull requests

2 participants