-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Enable cross project dbt ref support,
dbt mesh
, `multi po…
…rject dbt setup` (#49) * Enable multi project references and settings Revert "Enable multi project references and settings" This reverts commit 2686a19. * Enable multi project references and settings * Enable multi project references and settings
- Loading branch information
1 parent
7e91e6b
commit 4bede65
Showing
12 changed files
with
158 additions
and
1 deletion.
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
Empty file.
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,58 @@ | ||
from dataclasses import dataclass | ||
from pathlib import Path | ||
from typing import Mapping | ||
|
||
from dbt.config import RuntimeConfig | ||
from dbt.config.project import path_exists, _load_yaml | ||
from dbt.constants import DEPENDENCIES_FILE_NAME | ||
from dbt.exceptions import ( | ||
DbtProjectError, NonUniquePackageNameError, | ||
) | ||
from typing_extensions import override | ||
|
||
|
||
def load_yml_dict(file_path): | ||
ret = {} | ||
if path_exists(file_path): | ||
ret = _load_yaml(file_path) or {} | ||
return ret | ||
|
||
# pylint: disable=too-many-ancestors | ||
@dataclass | ||
class OpenDbtRuntimeConfig(RuntimeConfig): | ||
def load_dependence_projects(self): | ||
dependencies_yml_dict = load_yml_dict(f"{self.project_root}/{DEPENDENCIES_FILE_NAME}") | ||
|
||
if "projects" not in dependencies_yml_dict: | ||
return | ||
|
||
projects = dependencies_yml_dict["projects"] | ||
project_root_parent = Path(self.project_root).parent | ||
for project in projects: | ||
path = project_root_parent.joinpath(project['name']) | ||
try: | ||
project = self.new_project(str(path.as_posix())) | ||
except DbtProjectError as e: | ||
raise DbtProjectError( | ||
f"Failed to read depending project: {e} \n project path:{path.as_posix()}", | ||
result_type="invalid_project", | ||
path=path, | ||
) from e | ||
|
||
yield project.project_name, project | ||
|
||
@override | ||
def load_dependencies(self, base_only=False) -> Mapping[str, "RuntimeConfig"]: | ||
# if self.dependencies is None: | ||
|
||
if self.dependencies is None: | ||
# this sets self.dependencies variable! | ||
self.dependencies = super().load_dependencies(base_only=base_only) | ||
|
||
# additionally load `projects` defined in `dependencies.yml` | ||
for project_name, project in self.load_dependence_projects(): | ||
if project_name in self.dependencies: | ||
raise NonUniquePackageNameError(project_name) | ||
self.dependencies[project_name] = project | ||
|
||
return self.dependencies |
Empty file.
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,52 @@ | ||
from dataclasses import dataclass | ||
from pathlib import Path | ||
from typing import Mapping | ||
|
||
from dbt.config import RuntimeConfig | ||
from dbt.config.project import load_yml_dict | ||
from dbt.constants import DEPENDENCIES_FILE_NAME | ||
from dbt.exceptions import ( | ||
DbtProjectError, NonUniquePackageNameError, | ||
) | ||
from typing_extensions import override | ||
|
||
|
||
# pylint: disable=too-many-ancestors | ||
@dataclass | ||
class OpenDbtRuntimeConfig(RuntimeConfig): | ||
def load_dependence_projects(self): | ||
dependencies_yml_dict = load_yml_dict(f"{self.project_root}/{DEPENDENCIES_FILE_NAME}") | ||
|
||
if "projects" not in dependencies_yml_dict: | ||
return | ||
|
||
projects = dependencies_yml_dict["projects"] | ||
project_root_parent = Path(self.project_root).parent | ||
for project in projects: | ||
path = project_root_parent.joinpath(project['name']) | ||
try: | ||
project = self.new_project(str(path.as_posix())) | ||
except DbtProjectError as e: | ||
raise DbtProjectError( | ||
f"Failed to read depending project: {e} \n project path:{path.as_posix()}", | ||
result_type="invalid_project", | ||
path=path, | ||
) from e | ||
|
||
yield project.project_name, project | ||
|
||
@override | ||
def load_dependencies(self, base_only=False) -> Mapping[str, "RuntimeConfig"]: | ||
# if self.dependencies is None: | ||
|
||
if self.dependencies is None: | ||
# this sets self.dependencies variable! | ||
self.dependencies = super().load_dependencies(base_only=base_only) | ||
|
||
# additionally load `projects` defined in `dependencies.yml` | ||
for project_name, project in self.load_dependence_projects(): | ||
if project_name in self.dependencies: | ||
raise NonUniquePackageNameError(project_name) | ||
self.dependencies[project_name] = project | ||
|
||
return self.dependencies |
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,4 @@ | ||
|
||
target/ | ||
dbt_packages/ | ||
logs/ |
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,9 @@ | ||
name: 'dbtfinance' | ||
version: '1.0.0' | ||
|
||
profile: 'dbtfinance' | ||
|
||
# directories to be removed by `dbt clean` | ||
clean-targets: | ||
- "target" | ||
- "dbt_packages" |
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,7 @@ | ||
#packages: | ||
# - package: dbt-labs/dbt_utils | ||
# version: 1.1.1 | ||
|
||
# case-sensitive and matches the 'name' in the 'dbt_project.yml' | ||
projects: | ||
- name: dbtcore |
2 changes: 2 additions & 0 deletions
2
tests/resources/dbtfinance/models/my_cross_project_ref_model.sql
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,2 @@ | ||
|
||
select * from {{ ref('dbtcore', 'my_core_table1') }} |
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,15 @@ | ||
dbtfinance: | ||
outputs: | ||
dev: | ||
type: duckdb | ||
adapter: my.dbt.custom.OpenAdapterXXX | ||
path: ./../dev.duckdb | ||
threads: 1 | ||
|
||
prod: | ||
type: duckdb | ||
adapter: my.dbt.custom.OpenAdapterXXX | ||
path: prod.duckdb | ||
threads: 4 | ||
|
||
target: dev |
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