Skip to content

Commit

Permalink
separating hive tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benc-db committed Mar 5, 2025
1 parent ab93fd6 commit 0495d85
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
1 change: 1 addition & 0 deletions dbt/include/databricks/macros/relations/tags.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
{%- endmacro -%}

{% macro apply_tags(relation, set_tags, unset_tags=[]) -%}
{{ log("Applying tags to relation " ~ set_tags ~ " " ~ unset_tags) }}
{%- if (set_tags or unset_tags) and relation.is_hive_metastore() -%}
{{ exceptions.raise_compiler_error("Tags are only supported for Unity Catalog") }}
{%- endif -%}
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def pytest_addoption(parser):
parser.addoption("--profile", action="store", default="databricks_uc_sql_endpoint", type=str)
parser.addoption("--profile", action="store", default="databricks_cluster", type=str)


# Using @pytest.mark.skip_profile('databricks_cluster') uses the 'skip_by_adapter_type'
Expand Down
14 changes: 14 additions & 0 deletions tests/functional/adapter/views/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@
- name: msg
"""

hive_schema_yml = """
version: 2
models:
- name: initial_view
description: "This is a view"
config:
tblproperties:
key: value
columns:
- name: id
description: "This is the id column"
- name: msg
"""

altered_view_sql = """
{{ config(materialized='view') }}
select id from {{ ref('seed') }}
Expand Down
46 changes: 44 additions & 2 deletions tests/functional/adapter/views/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def models(self):

def test_view_update_with_description(self, project):
util.run_dbt(["build"])
schema_2 = fixtures.schema_yml.replace("This is a view", "This is an updated view")
schema = util.read_file("models", "schema.yml")
schema_2 = schema.replace("This is a view", "This is an updated view")
util.write_file(schema_2, "models", "schema.yml")
util.run_dbt(["run"])

Expand All @@ -41,7 +42,8 @@ def test_view_update_with_query(self, project):

def test_view_update_tblproperties(self, project):
util.run_dbt(["build"])
schema_2 = fixtures.schema_yml.replace("key: value", "key: value2")
schema = util.read_file("models", "schema.yml")
schema_2 = schema.replace("key: value", "key: value2")
util.write_file(schema_2, "models", "schema.yml")
util.run_dbt(["run"])

Expand All @@ -68,6 +70,7 @@ def project_config_update(self):
}


@pytest.mark.skip_profile("databricks_cluster")
class TestUpdateViewSafeReplace(BaseUpdateView):
@pytest.fixture(scope="class")
def project_config_update(self):
Expand All @@ -83,6 +86,7 @@ def project_config_update(self):
}


@pytest.mark.skip_profile("databricks_cluster")
class TestUpdateUnsafeReplace(BaseUpdateView):
@pytest.fixture(scope="class")
def project_config_update(self):
Expand All @@ -96,3 +100,41 @@ def project_config_update(self):
},
},
}


class HiveBaseUpdateView(BaseUpdateView):
@pytest.fixture(scope="class")
def models(self):
return {"initial_view.sql": fixtures.view_sql, "schema.yml": fixtures.hive_schema_yml}


@pytest.mark.skip_profile("databricks_uc_cluster", "databricks_uc_sql_endpoint")
class TestHiveUpdateViewSafeReplace(HiveBaseUpdateView):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"flags": {"use_materialization_v2": True},
"models": {
"+use_safer_relation_operations": True,
"+persist_docs": {
"relation": True,
"columns": True,
},
},
}


@pytest.mark.skip_profile("databricks_uc_cluster", "databricks_uc_sql_endpoint")
class TestHiveUpdateUnsafeReplace(HiveBaseUpdateView):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"flags": {"use_materialization_v2": True},
"models": {
"+use_safer_relation_operations": False,
"+persist_docs": {
"relation": True,
"columns": True,
},
},
}

0 comments on commit 0495d85

Please sign in to comment.