Dags in airflow are defined as python files. The dag below runs the dbt transformations defined in the jaffle_shop dbt project on a Teradata system using cosmos.Copy the python code below and save it as airflow-cosmos-dbt-teradata-integration.py under the directory $AIRFLOW_HOME/dags.
import os
from datetime import datetime
from airflow import DAG
from cosmos import DbtTaskGroup, ProjectConfig, ProfileConfig, ExecutionConfig
from cosmos.profiles import TeradataUserPasswordProfileMapping
PATH_TO_DBT_VENV = f"{os.environ['dbt_venv_dir']}"
PATH_TO_DBT_PROJECT = f"{os.environ['dbt_project_home_dir']}"
execution_config = ExecutionConfig(
dbt_executable_path=PATH_TO_DBT_VENV,
)
profile_config = ProfileConfig(
profile_name="generated_profile",
target_name="dev",
profile_mapping=TeradataUserPasswordProfileMapping(
conn_id="teradata_default",
),
)
with DAG(
dag_id="execute_dbt_transformations_with_cosmos",
max_active_runs=1,
max_active_tasks=10,
catchup=False,
start_date=datetime(2024, 1, 1),
) as dag:
transform_data = DbtTaskGroup(
group_id="transform_data",
project_config=ProjectConfig(PATH_TO_DBT_PROJECT),
profile_config=profile_config,
execution_config=execution_config,
default_args={"retries": 2},
)