-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow models to execute on different warehouses (#488)
- Loading branch information
Showing
5 changed files
with
457 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
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,50 @@ | ||
source = """id,name,date | ||
1,Alice,2022-01-01 | ||
2,Bob,2022-01-02 | ||
""" | ||
|
||
target = """ | ||
{{config(materialized='table', databricks_compute='alternate_warehouse')}} | ||
select * from {{ ref('source') }} | ||
""" | ||
|
||
target2 = """ | ||
{{config(materialized='table')}} | ||
select * from {{ ref('source') }} | ||
""" | ||
|
||
target3 = """ | ||
{{config(materialized='table')}} | ||
select * from {{ ref('source') }} | ||
""" | ||
|
||
model_schema = """ | ||
version: 2 | ||
models: | ||
- name: target | ||
columns: | ||
- name: id | ||
- name: name | ||
- name: date | ||
- name: target2 | ||
config: | ||
databricks_compute: alternate_warehouse | ||
columns: | ||
- name: id | ||
- name: name | ||
- name: date | ||
- name: target3 | ||
columns: | ||
- name: id | ||
- name: name | ||
- name: date | ||
""" | ||
|
||
expected_target = """id,name,date | ||
1,Alice,2022-01-01 | ||
2,Bob,2022-01-02 | ||
""" |
100 changes: 100 additions & 0 deletions
100
tests/functional/adapter/warehouse_per_model/test_warehouse_per_model.py
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,100 @@ | ||
import pytest | ||
from dbt.tests import util | ||
from tests.functional.adapter.warehouse_per_model import fixtures | ||
|
||
|
||
class BaseWarehousePerModel: | ||
args_formatter = "" | ||
|
||
@pytest.fixture(scope="class") | ||
def seeds(self): | ||
return { | ||
"source.csv": fixtures.source, | ||
} | ||
|
||
@pytest.fixture(scope="class") | ||
def models(self): | ||
d = dict() | ||
d["target4.sql"] = fixtures.target3 | ||
return { | ||
"target.sql": fixtures.target, | ||
"target2.sql": fixtures.target2, | ||
"target3.sql": fixtures.target3, | ||
"schema.yml": fixtures.model_schema, | ||
"special": d, | ||
} | ||
|
||
|
||
class BaseSpecifyingCompute(BaseWarehousePerModel): | ||
"""Base class for testing various ways to specify a warehouse.""" | ||
|
||
def test_wpm(self, project): | ||
util.run_dbt(["seed"]) | ||
models = project.test_config.get("model_names") | ||
for model_name in models: | ||
# Since the profile doesn't define a compute resource named 'alternate_warehouse' | ||
# we should fail with an error if the warehouse specified for the model is | ||
# correctly handled. | ||
res = util.run_dbt(["run", "--select", model_name], expect_pass=False) | ||
msg = res.results[0].message | ||
assert "Compute resource alternate_warehouse does not exist" in msg | ||
assert model_name in msg | ||
|
||
|
||
class TestSpecifyingInConfigBlock(BaseSpecifyingCompute): | ||
@pytest.fixture(scope="class") | ||
def test_config(self): | ||
return {"model_names": ["target"]} | ||
|
||
|
||
class TestSpecifyingInSchemaYml(BaseSpecifyingCompute): | ||
@pytest.fixture(scope="class") | ||
def test_config(self): | ||
return {"model_names": ["target2"]} | ||
|
||
|
||
class TestSpecifyingForProjectModels(BaseSpecifyingCompute): | ||
@pytest.fixture(scope="class") | ||
def project_config_update(self): | ||
return { | ||
"models": { | ||
"+databricks_compute": "alternate_warehouse", | ||
} | ||
} | ||
|
||
@pytest.fixture(scope="class") | ||
def test_config(self): | ||
return {"model_names": ["target3"]} | ||
|
||
|
||
class TestSpecifyingForProjectModelsInFolder(BaseSpecifyingCompute): | ||
@pytest.fixture(scope="class") | ||
def project_config_update(self): | ||
return { | ||
"models": { | ||
"test": { | ||
"special": { | ||
"+databricks_compute": "alternate_warehouse", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
@pytest.fixture(scope="class") | ||
def test_config(self): | ||
return {"model_names": ["target4"]} | ||
|
||
|
||
class TestWarehousePerModel(BaseWarehousePerModel): | ||
@pytest.fixture(scope="class") | ||
def profiles_config_update(self, dbt_profile_target): | ||
outputs = {"default": dbt_profile_target} | ||
outputs["default"]["compute"] = { | ||
"alternate_warehouse": {"http_path": dbt_profile_target["http_path"]} | ||
} | ||
return {"test": {"outputs": outputs, "target": "default"}} | ||
|
||
def test_wpm(self, project): | ||
util.run_dbt(["seed"]) | ||
util.run_dbt(["run", "--select", "target"]) | ||
util.check_relations_equal(project.adapter, ["target", "source"]) |
Oops, something went wrong.