Skip to content

Commit

Permalink
Merge pull request gocardless#26 from TimmyCarbone/snapshot-select
Browse files Browse the repository at this point in the history
Handle --select parameter for snapshots
  • Loading branch information
andrewrjones authored Sep 18, 2020
2 parents d4d914c + d7de44d commit e3aa3f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is a collection of [Airflow](https://airflow.apache.org/) operators to prov

```py
from airflow import DAG
from airflow_dbt.operators.dbt_operator import DbtRunOperator, DbtTestOperator
from airflow_dbt.operators.dbt_operator import DbtSnapshotOperator, DbtRunOperator, DbtTestOperator
from airflow.utils.dates import days_ago

default_args = {
Expand Down Expand Up @@ -67,6 +67,8 @@ Each of the above operators accept the following arguments:
* If set, passed as the `--models` argument to the `dbt` command
* `exclude`
* If set, passed as the `--exclude` argument to the `dbt` command
* `select`
* If set, passed as the `--select` argument to the `dbt` command
* `dbt_bin`
* The `dbt` CLI. Defaults to `dbt`, so assumes it's on your `PATH`
* `verbose`
Expand Down
7 changes: 7 additions & 0 deletions airflow_dbt/hooks/dbt_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class DbtCliHook(BaseHook):
:type models: str
:param exclude: If set, passed as the `--exclude` argument to the `dbt` command
:type exclude: str
:param select: If set, passed as the `--select` argument to the `dbt` command
:type select: str
:param dbt_bin: The `dbt` CLI. Defaults to `dbt`, so assumes it's on your `PATH`
:type dbt_bin: str
:param output_encoding: Output encoding of bash command. Defaults to utf-8
Expand All @@ -41,6 +43,7 @@ def __init__(self,
full_refresh=False,
models=None,
exclude=None,
select=None,
dbt_bin='dbt',
output_encoding='utf-8',
verbose=True):
Expand All @@ -51,6 +54,7 @@ def __init__(self,
self.full_refresh = full_refresh
self.models = models
self.exclude = exclude
self.select = select
self.dbt_bin = dbt_bin
self.verbose = verbose
self.output_encoding = output_encoding
Expand Down Expand Up @@ -86,6 +90,9 @@ def run_cli(self, *command):
if self.exclude is not None:
dbt_cmd.extend(['--exclude', self.exclude])

if self.select is not None:
dbt_cmd.extend(['--select', self.select])

if self.full_refresh:
dbt_cmd.extend(['--full-refresh'])

Expand Down
5 changes: 5 additions & 0 deletions airflow_dbt/operators/dbt_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class DbtBaseOperator(BaseOperator):
:type models: str
:param exclude: If set, passed as the `--exclude` argument to the `dbt` command
:type exclude: str
:param select: If set, passed as the `--select` argument to the `dbt` command
:type select: str
:param dbt_bin: The `dbt` CLI. Defaults to `dbt`, so assumes it's on your `PATH`
:type dbt_bin: str
:param verbose: The operator will log verbosely to the Airflow logs
Expand All @@ -40,6 +42,7 @@ def __init__(self,
vars=None,
models=None,
exclude=None,
select=None,
dbt_bin='dbt',
verbose=True,
full_refresh=False,
Expand All @@ -54,6 +57,7 @@ def __init__(self,
self.models = models
self.full_refresh = full_refresh
self.exclude = exclude
self.select = select
self.dbt_bin = dbt_bin
self.verbose = verbose
self.create_hook()
Expand All @@ -67,6 +71,7 @@ def create_hook(self):
full_refresh=self.full_refresh,
models=self.models,
exclude=self.exclude,
select=self.select,
dbt_bin=self.dbt_bin,
verbose=self.verbose)

Expand Down

0 comments on commit e3aa3f7

Please sign in to comment.