-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow models to execute on different warehouses #488
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know if we can specify a compute to use with models of a particular tag? This came up in a customer call where they would want to tag certain models as heavy_compute for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reading the dbt docs on tags, I don't think that would work, which is probably fine. I think having the named compute approach gets us 95% of the way to what it would be if they could target compute to tags.