-
Notifications
You must be signed in to change notification settings - Fork 296
[Guides] How cosmos runs dbt #2453
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
33deb72
First pass
lzdanski 2a7a9fa
Set up operators and how to run dbt
lzdanski 08001c3
Finish landing page draft
lzdanski 3225e01
update redirect
lzdanski be6ef68
Fix capitalization
lzdanski c817de5
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] 29fadfa
Fix typo
lzdanski 138de4f
Update based on feedback
lzdanski db63311
Restructure with more detail
lzdanski 13558cc
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
pre-commit-ci[bot] 10c6419
Fix codeblock formatting
lzdanski 10a1436
Apply suggestion from @tatiana
tatiana 29c7ad7
Apply suggestion from @tatiana
tatiana 0c3e5a9
Apply suggestion from @tatiana
tatiana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| .. _how-cosmos-runs-dbt: | ||
|
|
||
| How Cosmos runs dbt | ||
| =================== | ||
|
|
||
| Cosmos can run dbt commands directly using operators, or, after the dbt project has been parsed and turned into an Airflow Dag or task group, you can execute it. | ||
|
|
||
| In many execution modes, Cosmos’ ``DbtDag`` and ``DbtTaskGroup '' create a separate task for each dbt node (model, seed, snapshot). | ||
| This leads to improved visibility and the | ||
| possibility of fine-grained control over your dbt commands. For example, you can set task parameters like pool | ||
| or retries on individual Cosmos tasks. Or, you can make downstream tasks run as soon as a specific Cosmos task has finished successfully. | ||
| Running one dbt command per task can bring performance challenges, since each invocation of a dbt command incurs overhead. To improve performance, newer versions of Cosmos have introduced alternatives that offer the same level of granularity while centralising the execution of the dbt command in a single task. Check :ref:`watcher-execution-mode` and :ref:`async-execution-mode`, for more information. | ||
|
|
||
| Cosmos uses different kinds of configurations to control how the dbt nodes are executed within the Airflow Dag or task group, which you can customize based on your project and needs. | ||
|
|
||
| Execution modes | ||
| ~~~~~~~~~~~~~~~~ | ||
|
|
||
| Execution modes are defined by the ``ExecutionConfig`` class in your Cosmos Dag. | ||
| Depending on your specific dbt project architecture and whether you want to run your dbt commands in the cloud or in a container separate from your Airflow environment. | ||
|
|
||
| Check out the available :ref:`execution-modes` and the detailed :ref:`execution-config` for more information about how to set up your Cosmos execution. | ||
|
|
||
|
|
||
| Running dbt commands | ||
| ~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| In addition to specifying where you want Cosmos to run dbt commands, you can also configure the following: | ||
|
|
||
| - :ref:`callbacks`: Tell Cosmos how to handle artifacts produced by dbt while executing dbt code. | ||
| - ``interceptor``: (new in v1.14) Optional list of callables run before building the dbt command. See :ref:`operator-args` or for more information. | ||
| - :ref:`operator-args`: Pass specific operator arguments, ``operator_args``, in your Dag that can directly correspond to dbt commands, Cosmos operations, or to define Airflow behavior. | ||
| - :ref:`scheduling`: Leverage Airflow to schedule your dbt workflows with cron-based scheduling, timetables, and data-aware scheduling. | ||
| - :ref:`partial-parsing`: Configure Cosmos to use dbt's partial parsing capabilities, improving dbt and Dag parsing, which speeds up execution times. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
| .. _operator-index: | ||
|
|
||
| Operators | ||
| ========= | ||
|
|
||
| Learn how to use operators with Cosmos. | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 1 | ||
| :caption: Operators | ||
|
|
||
| operators | ||
| operator-args | ||
| overriding-operator-args |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
docs/guides/run_dbt/operators/overriding-operator-args.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| .. _operator-args-per-node: | ||
|
|
||
| Overriding operator arguments per dbt node (or group of nodes) | ||
| ============================================================== | ||
|
|
||
| .. versionadded:: 1.8.0 | ||
|
|
||
| Cosmos 1.8 introduced the capability for users to customise the operator arguments per dbt node, or per group of dbt nodes. | ||
| This can be done by defining the arguments via a dbt meta property alongside other dbt project configurations. | ||
|
|
||
| Let's say there is a DbtTaskGroup that sets a default pool to run all the dbt tasks, but a user would like the model expensive | ||
| to run a separate pool. | ||
|
|
||
| Users could either use ``operator_args`` or ``default args`` for defining the default behavior: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| dbt_task_group = DbtTaskGroup( | ||
| # ... | ||
| profile_config=ProfileConfig, | ||
| default_args={"pool": "default_pool"}, | ||
| ) | ||
|
|
||
| While configuring in the ``dbt_project.yml`` a different behaviour for the model "expensive", that should use the "expensive-pool": | ||
|
|
||
| .. code-block:: | ||
|
|
||
| version: 2 | ||
| models: | ||
| - name: expensive | ||
| description: description | ||
| meta: | ||
| cosmos: | ||
| operator_kwargs: | ||
| pool: expensive-pool | ||
|
|
||
|
|
||
| More information about this feature can be found in :ref:`custom-airflow-properties`. | ||
|
|
||
| To learn how to customise the profile per dbt model or Cosmos task, check :ref:`profile-customise-per-node`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| .. _execution-config: | ||
|
|
||
| Execution Config | ||
| ================== | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.