Skip to content

Commit 3e41041

Browse files
committed
docs: update docstring
1 parent 035f7b1 commit 3e41041

File tree

2 files changed

+92
-7
lines changed

2 files changed

+92
-7
lines changed

airflow_dbt_python/operators/dbt.py

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import datetime as dt
66
import os
7+
from abc import ABC, abstractmethod
78
from dataclasses import asdict, is_dataclass
89
from pathlib import Path
910
from typing import TYPE_CHECKING, Any, Dict, Optional, Union
@@ -38,18 +39,84 @@ class DbtBaseOperator(BaseOperator):
3839
command itself, subclasses should set it.
3940
4041
Attributes:
41-
command: The dbt command to execute.
4242
project_dir: Directory for dbt to look for dbt_profile.yml. Defaults to
4343
current directory.
4444
profiles_dir: Directory for dbt to look for profiles.yml. Defaults to
4545
~/.dbt.
4646
profile: Which profile to load. Overrides dbt_profile.yml.
4747
target: Which target to load for the given profile.
48+
state: Unless overridden, use this state directory for both state comparison
49+
and deferral.
50+
cache_selected_only: At start of run, populate relational cache
51+
only for schemas containing selected nodes, or for all schemas of interest.
52+
fail_fast: Stop execution on first failure.
53+
single_threaded: Execute dbt command in single threaded mode. For test only
54+
threads: Specify number of threads to use while executing models.
55+
Overrides settings in profiles.yml.
56+
use_experimental_parser: Enable experimental parsing features.
4857
vars: Supply variables to the project. Should be a YAML string. Overrides
4958
variables defined in dbt_profile.yml.
59+
warn_error: If dbt would normally warn, instead raise an exception.
60+
Examples include --select that selects nothing, deprecations,
61+
configurations with no associated models, invalid test configurations,
62+
and missing sources/refs in tests.
63+
debug: Display debug logging during dbt execution.
64+
Useful for debugging and making bug reports.
65+
log_path: Log path for dbt execution.
66+
log_level: Specify the minimum severity of events that are logged
67+
to the console and the log file.
68+
log_level_file: Specify the minimum severity of events that are logged
69+
to the log file by overriding the default value
70+
log_format: Specify the format of logging to the console and the log file.
71+
log_format_file: Specify the format of logging to the log file by overriding
72+
the default value
5073
log_cache_events: Flag to enable logging of cache events.
51-
s3_conn_id: An s3 Airflow connection ID to use when pulling dbt files from s3.
74+
quiet/no_quiet: Suppress all non-error logging to stdout.
75+
Does not affect {{ print() }} macro calls.
76+
print/no_print: Output all {{ print() }} macro calls.
77+
record_timing_info: When this option is passed, dbt will output low-level
78+
timing stats to the specified file.
79+
defer/no_defer: If set, resolve unselected nodes by deferring to the manifest
80+
within the --state directory.
81+
partial_parse/no_partial_parse: Allow for partial parsing by looking for
82+
and writing to a pickle file in the target directory.
83+
introspect/no_introspect: Whether to scaffold introspective queries
84+
as part of compilation
85+
use_colors/no_use_colors: Specify whether log output is colorized
86+
in the console and the log file.
87+
static_parser/no_static_parser: Use the static parser.
88+
version_check/no_version_check: If set, ensure the installed dbt version matches
89+
the require-dbt-version specified in the dbt_project.yml file (if any).
90+
Otherwise, allow them to differ.
91+
write_json/no_write_json: Whether or not to write the manifest.json
92+
and run_results.json files to the target directory
93+
send_anonymous_usage_stats/no_send_anonymous_usage_stats: Send anonymous usage
94+
stats to dbt Labs.
95+
partial_parse_file_diff/no_partial_parse_file_diff: Internal flag for whether
96+
to compute a file diff during partial parsing.
97+
inject_ephemeral_ctes/no_inject_ephemeral_ctes: Internal flag controlling
98+
injection of referenced ephemeral models' CTEs during `compile`.
99+
empty/no_empty: If specified, limit input refs and sources to zero rows.
100+
show_resource_report/no_show_resource_report: If set, dbt will output
101+
resource report into log.
102+
favor_state/no_favor_state: If set, defer to the argument provided to
103+
the state flag for resolving unselected nodes, even if the node(s) exist
104+
as a database object in the current environment.
105+
export_saved_queries/no_export_saved_queries: Export saved queries within
106+
the 'build' command, otherwise no-op
107+
dbt_conn_id: An Airflow connection ID to generate dbt profile from.
108+
profiles_conn_id: An Airflow connection ID to use for pulling dbt profiles
109+
from remote (e.g. git/s3/gcs).
110+
project_conn_id: An Airflow connection ID to use for pulling dbt project
111+
from remote (e.g. git/s3/gcs).
52112
do_xcom_push_artifacts: A list of dbt artifacts to XCom push.
113+
upload_dbt_project: Flag to enable unloading the project dbt after the operator
114+
execution back to project_dir.
115+
delete_before_upload: Flag to enable cleaning up project_dir before uploading
116+
dbt project back to.
117+
replace_on_upload: Flag to allow replacing files when uploading dbt project
118+
back to project_dir.
119+
env_vars: Supply environment variables to the project
53120
"""
54121

55122
template_fields = base_template_fields
@@ -77,6 +144,7 @@ def __init__(
77144
log_level: Optional[str] = None,
78145
log_level_file: Optional[str] = None,
79146
log_format: LogFormat = LogFormat.DEFAULT,
147+
log_format_file: LogFormat = LogFormat.DEBUG,
80148
log_cache_events: Optional[bool] = False,
81149
quiet: Optional[bool] = None,
82150
no_quiet: Optional[bool] = None,
@@ -149,6 +217,7 @@ def __init__(
149217
self.log_level = log_level
150218
self.log_level_file = log_level_file
151219
self.log_format = log_format
220+
self.log_format_file = log_format_file
152221
self.record_timing_info = record_timing_info
153222

154223
self.dbt_defer = defer
@@ -243,6 +312,7 @@ def execute(self, context):
243312
return serializable_result
244313

245314
@property
315+
@abstractmethod
246316
def command(self) -> str:
247317
"""Return the current dbt command.
248318
@@ -296,6 +366,22 @@ def make_run_results_serializable(
296366
return asdict(result, dict_factory=run_result_factory)
297367

298368

369+
class _GraphRunnableOperator(ABC, DbtBaseOperator):
370+
"""The abstract base Airflow dbt operator for list/compile commands.
371+
372+
Attributes:
373+
compiled_target:
374+
"""
375+
376+
def __init__(
377+
self,
378+
compiled_target: Optional[Union[os.PathLike, str, bytes]] = None,
379+
**kwargs,
380+
):
381+
super().__init__(**kwargs)
382+
self.compiled_target = compiled_target
383+
384+
299385
selection_template_fields = ["select", "exclude"]
300386

301387

@@ -397,7 +483,7 @@ def command(self) -> str:
397483
return "test"
398484

399485

400-
class DbtCompileOperator(DbtBaseOperator):
486+
class DbtCompileOperator(_GraphRunnableOperator):
401487
"""Executes a dbt compile command.
402488
403489
The compile command generates SQL files. The
@@ -542,7 +628,7 @@ def command(self) -> str:
542628
return "snapshot"
543629

544630

545-
class DbtLsOperator(DbtBaseOperator):
631+
class DbtLsOperator(_GraphRunnableOperator):
546632
"""Executes a dbt list (or ls) command.
547633
548634
The documentation for the dbt command can be found here:

tests/operators/test_dbt_base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@
77

88
def test_dbt_base_does_not_implement_command():
99
"""Test DbtBaseOperator doesn't implement a command."""
10-
op = DbtBaseOperator(task_id="dbt_task")
11-
with pytest.raises(NotImplementedError):
12-
op.command
10+
with pytest.raises(TypeError):
11+
DbtBaseOperator(task_id="dbt_task")

0 commit comments

Comments
 (0)