Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Add DbtCleanOperator #47

Merged
merged 2 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ from airflow_dbt.operators.dbt_operator import (
DbtSeedOperator,
DbtSnapshotOperator,
DbtRunOperator,
DbtTestOperator
DbtTestOperator,
DbtCleanOperator,
)
from airflow.utils.dates import days_ago

Expand Down Expand Up @@ -36,7 +37,11 @@ with DAG(dag_id='dbt', default_args=default_args, schedule_interval='@daily') as
retries=0, # Failing tests would fail the task, and we don't want Airflow to try again
)

dbt_seed >> dbt_snapshot >> dbt_run >> dbt_test
dbt_clean = DbtCleanOperator(
task_id='dbt_clean,
)

dbt_seed >> dbt_snapshot >> dbt_run >> dbt_test >> dbt_clean
```

## Installation
Expand Down Expand Up @@ -65,6 +70,8 @@ There are five operators currently implemented:
* Calls [`dbt run`](https://docs.getdbt.com/docs/run)
* `DbtTestOperator`
* Calls [`dbt test`](https://docs.getdbt.com/docs/test)
* `DbtCleanOperator`
* Calls [`dbt clean`](https://docs.getdbt.com/docs/clean)


Each of the above operators accept the following arguments:
Expand Down
9 changes: 9 additions & 0 deletions airflow_dbt/operators/dbt_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,12 @@ def __init__(self, profiles_dir=None, target=None, *args, **kwargs):

def execute(self, context):
self.create_hook().run_cli('deps')


class DbtCleanOperator(DbtBaseOperator):
@apply_defaults
def __init__(self, profiles_dir=None, target=None, *args, **kwargs):
super(DbtCleanOperator, self).__init__(profiles_dir=profiles_dir, target=target, *args, **kwargs)

def execute(self, context):
self.create_hook().run_cli('clean')
12 changes: 11 additions & 1 deletion tests/operators/test_dbt_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
DbtSnapshotOperator,
DbtRunOperator,
DbtTestOperator,
DbtDepsOperator
DbtDepsOperator,
DbtCleanOperator,
)


Expand Down Expand Up @@ -64,3 +65,12 @@ def test_dbt_deps(self, mock_run_cli):
)
operator.execute(None)
mock_run_cli.assert_called_once_with('deps')

@mock.patch.object(DbtCliHook, 'run_cli')
def test_dbt_clean(self, mock_run_cli):
operator = DbtCleanOperator(
task_id='clean',
dag=self.dag
)
operator.execute(None)
mock_run_cli.assert_called_once_with('clean')