Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benc-db committed Nov 29, 2023
1 parent 86d5e56 commit 98f7583
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Adding capability to specify compute on a per model basis ([488](https://github.com/databricks/dbt-databricks/pull/488))
- Selectively persist column docs that have changed between runs of incremental ([513](https://github.com/databricks/dbt-databricks/pull/513))
- Enabling access control list for job runs (thanks @srggrs!)([518](https://github.com/databricks/dbt-databricks/pull/518))
- Allow persisting of column docs on views ([519](https://github.com/databricks/dbt-databricks/pull/519))

## dbt-databricks 1.7.1 (Nov 13, 2023)

Expand Down
23 changes: 20 additions & 3 deletions dbt/include/databricks/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,31 @@
{%- endif -%}
{%- endmacro -%}

{% macro get_column_comment_sql(column_name, column_dict) -%}
{% if column_name in column_dict and column_dict[column_name]["description"] -%}
{% set escaped_description = column_dict[column_name]["description"] | replace("'", "\\'") %}
{% set column_comment_clause = "comment '" ~ escaped_description ~ "'" %}
{%- endif -%}
{{ adapter.quote(column_name) }} {{ column_comment_clause }}
{% endmacro %}

{% macro get_persist_docs_column_list(model_columns, query_columns) %}
{% for column_name in query_columns %}
{{ get_column_comment_sql(column_name, model_columns) }}
{{- ", " if not loop.last else "" }}
{% endfor %}
{% endmacro %}

{% macro databricks__create_view_as(relation, sql) -%}
create or replace view {{ relation }}
{% if config.persist_column_docs() -%}
{% set model_columns = model.columns %}
{% set query_columns = get_columns_in_query(sql) %}
(
{{ get_persist_docs_column_list(model_columns, query_columns) }}
)
{% if query_columns %}
(
{{ get_persist_docs_column_list(model_columns, query_columns) }}
)
{% endif %}
{% endif %}
{{ comment_clause() }}
{%- set contract_config = config.get('contract') -%}
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/macros/test_adapters_macros.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from mock import MagicMock
from dbt.adapters.databricks.relation import DatabricksRelation

from tests.unit.macros.base import TestMacros
Expand Down Expand Up @@ -210,7 +211,7 @@ def test_macros_create_table_as_all_hudi(self):
def test_macros_create_view_as_tblproperties(self):
self.config["tblproperties"] = {"tblproperties_to_view": "true"}
self.default_context["model"].alias = "my_table"

self.default_context["get_columns_in_query"] = MagicMock(return_value=[])
sql = self._run_macro("databricks__create_view_as", "my_table", "select 1")

self.assertEqual(
Expand Down

0 comments on commit 98f7583

Please sign in to comment.