-
Notifications
You must be signed in to change notification settings - Fork 170
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
Add dbt clone operator #1326
Open
pankajastro
wants to merge
3
commits into
main
Choose a base branch
from
dbt_clone
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add dbt clone operator #1326
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
from cosmos.operators.base import ( | ||
AbstractDbtBaseOperator, | ||
DbtBuildMixin, | ||
DbtCloneMixin, | ||
DbtLSMixin, | ||
DbtRunMixin, | ||
DbtRunOperationMixin, | ||
|
@@ -167,3 +168,12 @@ class DbtRunOperationAzureContainerInstanceOperator(DbtRunOperationMixin, DbtAzu | |
|
||
def __init__(self, *args: Any, **kwargs: Any) -> None: | ||
super().__init__(*args, **kwargs) | ||
|
||
|
||
class DbtCloneAzureContainerInstanceOperator(DbtCloneMixin, DbtAzureContainerInstanceBaseOperator): | ||
""" | ||
Executes a dbt core clone command. | ||
""" | ||
|
||
def __init__(self, *args: Any, **kwargs: Any): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same feedback given on https://github.com/astronomer/astronomer-cosmos/pull/1326/files#r1843904192 applies here and in the other |
||
super().__init__(*args, **kwargs) |
This file contains 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 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 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 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 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 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 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 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,57 @@ | ||
import os | ||
from datetime import datetime | ||
from pathlib import Path | ||
|
||
from airflow import DAG | ||
|
||
from cosmos import DbtCloneLocalOperator, DbtRunLocalOperator, DbtSeedLocalOperator, ProfileConfig | ||
|
||
DEFAULT_DBT_ROOT_PATH = Path(__file__).parent / "dbt" | ||
DBT_ROOT_PATH = Path(os.getenv("DBT_ROOT_PATH", DEFAULT_DBT_ROOT_PATH)) | ||
DBT_PROJ_DIR = DBT_ROOT_PATH / "jaffle_shop" | ||
DBT_PROFILE_PATH = DBT_ROOT_PATH / "profiles.yml" | ||
DBT_ARTIFACT = DBT_ROOT_PATH / "target" | ||
|
||
profile_config1 = ProfileConfig( | ||
profile_name="bigquery_dev", | ||
target_name="dev", | ||
profiles_yml_filepath=DBT_PROFILE_PATH, | ||
) | ||
|
||
profile_config2 = ProfileConfig( | ||
profile_name="bigquery_clone", | ||
target_name="dev", | ||
profiles_yml_filepath=DBT_PROFILE_PATH, | ||
) | ||
|
||
|
||
with DAG("example_operators", start_date=datetime(2024, 1, 1), catchup=False) as dag: | ||
seed_operator = DbtSeedLocalOperator( | ||
profile_config=profile_config1, | ||
project_dir=DBT_PROJ_DIR, | ||
task_id="seed", | ||
dbt_cmd_flags=["--select", "raw_customers"], | ||
install_deps=True, | ||
append_env=True, | ||
) | ||
run_operator = DbtRunLocalOperator( | ||
profile_config=profile_config1, | ||
project_dir=DBT_PROJ_DIR, | ||
task_id="run", | ||
dbt_cmd_flags=["--models", "stg_customers"], | ||
install_deps=True, | ||
append_env=True, | ||
) | ||
|
||
# [START clone_example] | ||
clone_operator = DbtCloneLocalOperator( | ||
profile_config=profile_config2, | ||
project_dir=DBT_PROJ_DIR, | ||
task_id="clone", | ||
dbt_cmd_flags=["--models", "stg_customers", "--state", DBT_ARTIFACT], | ||
install_deps=True, | ||
append_env=True, | ||
) | ||
# [END clone_example] | ||
|
||
seed_operator >> run_operator >> clone_operator |
This file contains 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 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,24 @@ | ||
.. _operators: | ||
|
||
Operators | ||
========= | ||
|
||
Cosmos exposes individual operators that correspond to specific dbt commands, which can be used just like traditional | ||
`Apache Airflow® <https://airflow.apache.org/>`_ operators. Cosmos names these operators using the format ``Dbt<dbt-command><execution-mode>Operator``. For example, ``DbtBuildLocalOperator``. | ||
|
||
Clone | ||
----- | ||
|
||
Requirement | ||
|
||
* Cosmos >= 1.8.0 | ||
* dbt-core >= 1.6.0 | ||
|
||
The ``DbtCloneLocalOperator`` implement `dbt clone <https://docs.getdbt.com/reference/commands/clone>`_ command. | ||
|
||
Example of how to use | ||
|
||
.. literalinclude:: ../../dev/dags/example_operators.py | ||
:language: python | ||
:start-after: [START clone_example] | ||
:end-before: [END clone_example] |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What value is the constructor giving us? Would it make sense to do something like this: