Skip to content

Commit

Permalink
tglunde#80 Disable view comments outside of DDL (tglunde#82)
Browse files Browse the repository at this point in the history
* tglunde#80 disable comments on views outside DDL

* tglunde#80 relation comment

* tglunde#80 whitespace control

* added view test with persist docs enabled

---------

Co-authored-by: Torsten Glunde <torsten.glunde@alligator-company.com>
  • Loading branch information
2 people authored and Peter Kioko committed Nov 9, 2023
1 parent be1e11f commit 560d12b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
12 changes: 9 additions & 3 deletions dbt/include/exasol/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,11 @@ AS
{% endmacro %}

{% macro exasol__alter_relation_comment(relation, relation_comment) -%}
{%- set comment = relation_comment | replace("'", '"') %}
COMMENT ON {{ relation.type }} {{ relation }} IS '{{ comment }}';
{# Comments on views are not supported outside DDL, see https://docs.exasol.com/db/latest/sql/comment.htm#UsageNotes #}
{%- if not relation.is_view %}
{%- set comment = relation_comment | replace("'", '"') %}
COMMENT ON {{ relation.type }} {{ relation }} IS '{{ comment }}';
{%- endif %}
{% endmacro %}

{% macro get_column_comment_sql(column_name, column_dict, apply_comment=false) -%}
Expand All @@ -145,12 +148,15 @@ AS
{%- endmacro %}

{% macro exasol__alter_column_comment(relation, column_dict) -%}
{# Comments on views are not supported outside DDL, see https://docs.exasol.com/db/latest/sql/comment.htm#UsageNotes #}
{%- if not relation.is_view %}
{% set query_columns = get_columns_in_query(sql) %}
COMMENT ON {{ relation.type }} {{ relation }} (
{% for column_name in query_columns %}
{{ get_column_comment_sql(column_name, column_dict) }} {{- ',' if not loop.last }}
{{ get_column_comment_sql(column_name, column_dict) }} {{- ',' if not loop.last }}
{% endfor %}
);
{%- endif %}
{% endmacro %}

{% macro persist_view_column_docs(relation, sql) %}
Expand Down
26 changes: 26 additions & 0 deletions tests/functional/test_view_comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from dbt.tests.adapter.basic.test_generic_tests import BaseGenericTests
import pytest

from dbt.tests.adapter.basic.files import (
base_table_sql,
schema_base_yml,
generic_test_view_yml,
generic_test_table_yml,
)

class TestExasolViewComment(BaseGenericTests):
@pytest.fixture(scope="class")
def models(self):
return {
"view_model.sql": """
{{config(
materialized='view',
persist_docs={"relation": true, "columns": true }
)}}
select * from {{ source('raw', 'seed') }}
""",
"table_model.sql": base_table_sql,
"schema.yml": schema_base_yml,
"schema_view.yml": generic_test_view_yml,
"schema_table.yml": generic_test_table_yml,
}

0 comments on commit 560d12b

Please sign in to comment.