-
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.
- Loading branch information
Showing
7 changed files
with
128 additions
and
12 deletions.
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
6 changes: 1 addition & 5 deletions
6
dbt/include/databricks/macros/relations/materialized_view/refresh.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 |
---|---|---|
@@ -1,7 +1,3 @@ | ||
{% macro get_refresh_materialized_view_sql(relation) -%} | ||
{{ adapter.dispatch('get_refresh_materialized_view_sql', 'dbt')(relation) }} | ||
{%- endmacro %} | ||
|
||
{% macro databricks__get_refresh_materialized_view_sql(relation) -%} | ||
{% macro databricks__refresh_materialized_view(relation) -%} | ||
refresh materialized view {{ relation }} | ||
{% endmacro %} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
databricks-sql-connector>=3.1.0, <3.2.0 | ||
dbt-spark>=1.8.0b1 | ||
dbt-spark~=1.8.0b1 | ||
databricks-sdk==0.17.0 | ||
keyring>=23.13.0 | ||
pandas<2.2.0 |
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
96 changes: 96 additions & 0 deletions
96
tests/functional/adapter/materialized_view_tests/test_changes.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,96 @@ | ||
from typing import Optional | ||
from dbt.tests.adapter.materialized_view.changes import ( | ||
MaterializedViewChanges, | ||
MaterializedViewChangesApplyMixin, | ||
MaterializedViewChangesContinueMixin, | ||
MaterializedViewChangesFailMixin, | ||
) | ||
from dbt.adapters.base import BaseRelation | ||
from dbt.tests import util | ||
import pytest | ||
from dbt.adapters.databricks.relation_configs.materialized_view import MaterializedViewConfig | ||
from dbt.adapters.databricks.relation_configs.tblproperties import TblPropertiesConfig | ||
|
||
from tests.functional.adapter.materialized_view_tests import fixtures | ||
|
||
|
||
def _check_tblproperties(tblproperties: TblPropertiesConfig, expected: dict): | ||
final_tblproperties = { | ||
k: v for k, v in tblproperties.tblproperties.items() if not k.startswith("pipeline") | ||
} | ||
assert final_tblproperties == expected | ||
|
||
|
||
class MaterializedViewChangesMixin(MaterializedViewChanges): | ||
@pytest.fixture(scope="class", autouse=True) | ||
def models(self): | ||
return {"my_materialized_view.sql": fixtures.materialized_view} | ||
|
||
@staticmethod | ||
def check_start_state(project, materialized_view): | ||
with util.get_connection(project.adapter): | ||
results = project.adapter.get_relation_config(materialized_view) | ||
assert isinstance(results, MaterializedViewConfig) | ||
assert results.config["partition_by"].partition_by == ["id"] | ||
assert results.config["query"].query.startswith("select * from") | ||
_check_tblproperties(results.config["tblproperties"], {"key": "value"}) | ||
assert results.config["refresh"].cron == "0 0 * * * ? *" | ||
assert results.config["refresh"].time_zone_value == "Etc/UTC" | ||
|
||
@staticmethod | ||
def change_config_via_alter(project, materialized_view): | ||
initial_model = util.get_model_file(project, materialized_view) | ||
new_model = initial_model.replace("'cron': '0 0 * * * ? *'", "'cron': '0 5 * * * ? *'") | ||
util.set_model_file(project, materialized_view, new_model) | ||
|
||
@staticmethod | ||
def check_state_alter_change_is_applied(project, materialized_view): | ||
with util.get_connection(project.adapter): | ||
results = project.adapter.get_relation_config(materialized_view) | ||
assert isinstance(results, MaterializedViewConfig) | ||
assert results.config["refresh"].cron == "0 5 * * * ? *" | ||
assert results.config["refresh"].time_zone_value == "Etc/UTC" | ||
|
||
@staticmethod | ||
def change_config_via_replace(project, materialized_view): | ||
initial_model = util.get_model_file(project, materialized_view) | ||
new_model = ( | ||
initial_model.replace("partition_by='id',", "") | ||
.replace("select *", "select id, value") | ||
.replace("'key': 'value'", "'other': 'other'") | ||
) | ||
util.set_model_file(project, materialized_view, new_model) | ||
|
||
@staticmethod | ||
def check_state_replace_change_is_applied(project, materialized_view): | ||
with util.get_connection(project.adapter): | ||
results = project.adapter.get_relation_config(materialized_view) | ||
assert isinstance(results, MaterializedViewConfig) | ||
assert results.config["partition_by"].partition_by == [] | ||
assert results.config["query"].query.startswith("select id, value") | ||
_check_tblproperties(results.config["tblproperties"], {"other": "other"}) | ||
|
||
@staticmethod | ||
def query_relation_type(project, relation: BaseRelation) -> Optional[str]: | ||
return fixtures.query_relation_type(project, relation) | ||
|
||
|
||
@pytest.mark.skip_profile("databricks_cluster", "databricks_uc_cluster") | ||
class TestMaterializedViewApplyChanges( | ||
MaterializedViewChangesMixin, MaterializedViewChangesApplyMixin | ||
): | ||
pass | ||
|
||
|
||
@pytest.mark.skip_profile("databricks_cluster", "databricks_uc_cluster") | ||
class TestMaterializedViewContinueOnChanges( | ||
MaterializedViewChangesMixin, MaterializedViewChangesContinueMixin | ||
): | ||
pass | ||
|
||
|
||
@pytest.mark.skip_profile("databricks_cluster", "databricks_uc_cluster") | ||
class TestMaterializedViewFailOnChanges( | ||
MaterializedViewChangesMixin, MaterializedViewChangesFailMixin | ||
): | ||
pass |